包不可见错误
我在包可见性方面遇到了麻烦。我有一个非常简单的包,代码如下所示。错误消息如下所示:
viterbi.adb:12:14: "Integer_Text_IO" is not visible (more references follow)
viterbi.adb:12:14: non-visible declaration at a-inteio.ads:18
gnatmake: "viterbi.adb" compilation error
程序包规范如下:
package Viterbi is
procedure Load_N_File(
Filename : in String;
N : in out Integer;
M : in out Integer);
end Viterbi;
程序包主体如下:
with Ada.Integer_Text_IO; use with Ada.Integer_Text_IO;
with Ada.Strings; use Ada.Strings;
package body Viterbi is
procedure Load_N_File(
Filename : in String;
N : in out Integer;
M : in out Integer
) is
N_File : File_Type;
begin
Open( N_File, Mode=>In_File, Name=>Filename );
Get( N_File, N );
Get( N_File, M );
Close( N_File );
end Load_N_File;
end Viterbi;
我的程序包主体中的什么导致程序包保持隐藏状态? use 子句不应该将 Integer_Text_IO 引入视图吗?
I've having trouble with package visibility. I have a really simple package and the code is listed below. The error message is shown here:
viterbi.adb:12:14: "Integer_Text_IO" is not visible (more references follow)
viterbi.adb:12:14: non-visible declaration at a-inteio.ads:18
gnatmake: "viterbi.adb" compilation error
The package specification is as follows:
package Viterbi is
procedure Load_N_File(
Filename : in String;
N : in out Integer;
M : in out Integer);
end Viterbi;
The package body is as follows:
with Ada.Integer_Text_IO; use with Ada.Integer_Text_IO;
with Ada.Strings; use Ada.Strings;
package body Viterbi is
procedure Load_N_File(
Filename : in String;
N : in out Integer;
M : in out Integer
) is
N_File : File_Type;
begin
Open( N_File, Mode=>In_File, Name=>Filename );
Get( N_File, N );
Get( N_File, M );
Close( N_File );
end Load_N_File;
end Viterbi;
What in my package body is causing the package to stay hidden? Shouldn't the use clause bring Integer_Text_IO into view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
提供的包体代码存在语法错误:“use with Ada.Integer_Text_IO;”中的虚假“with”条款。
修复此问题后,我收到了围绕无法解析 File_Type、Open 和 Close 的编译错误。添加 Ada.Text_IO 的“with”和“use”给了我一个干净的编译。
所以包体的开头看起来像:
如果修复这些错误后仍然出现“找不到 Integer_Text_IO”错误,那么我会对您的开发环境产生怀疑,即所有内容是否都安装正确?
The code of the package body as provided has a syntax error: the spurious "with" in the "use with Ada.Integer_Text_IO;" clause.
Having fixed that, I then get compilation errors revolving around the inability to resolve File_Type, Open, and Close. Adding a "with" and "use" of Ada.Text_IO gives me a clean compilation.
So the start of the package body looks like:
If you're still getting a "can't find Integer_Text_IO" error after fixing these errors, then I'd be suspicious about your development environment, i.e. is everything installed correctly?
正如已经指出的,通过使用逗号分隔样式,您可以避免“use with”样式的错误:
和
-- 测试,
Ada.Integer_Text_IO,
艾达.字符串;
这还允许您注释掉特定的包“withs”或“usues”,如图所示。
You can avoid the "use with" style of error, as already pointed out, by using the comma-separated style:
With
-- Testing,
Ada.Integer_Text_IO,
Ada.Strings;
this also allows you to comment out specific package 'withs' or 'usues' as shown.