Ada 包不可见错误
我的包可见性有问题。我有一个非常简单的包,下面列出了代码。错误消息如下所示:Ada 包不可见错误,ada,gnat,Ada,Gnat,我的包可见性有问题。我有一个非常简单的包,下面列出了代码。错误消息如下所示: 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
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;
包体如下:
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\u Text\u IO带入视图吗?提供的包体代码有一个语法错误:“use with Ada.Integer\u Text\u IO;”子句中的伪“with” 解决了这个问题后,我发现编译错误围绕着无法解析文件类型、打开和关闭。添加Ada.Text_IO的“with”和“use”可以让我得到一个干净的编译 因此,包体的开头看起来像:
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Strings; use Ada.Strings;
with Ada.Text_IO; use Ada.Text_IO;
package body Viterbi is
...
如果在修复这些错误后仍然出现“找不到整型\u Text\u IO”错误,那么我会怀疑您的开发环境,即是否所有内容都正确安装?您可以使用逗号分隔的样式避免前面指出的“与一起使用”样式的错误:
具有
--测试,
Ada.Integer\u Text\u IO,
Ada.字符串
Use
-- Testing,
Ada.Strings,
Ada.Integer_Text_IO;
这也允许您注释特定的软件包“with”或“usues”,如图所示。谢谢,我不敢相信我漏掉了额外的“with”。删除它并没有使错误消失,但添加Ada.Text_IO包并将其放到视图中解决了错误。再次感谢。许多人不同意我的观点,但我通常建议人们先编写代码,不要使用任何
use
子句。当它完成后,你进入清理阶段,然后你可以把它们放回去,如果它使代码更清晰的话。他们的问题是,他们允许你懒惰到这样的地步,你会遇到上面提到的问题,你会把头发拔出来,因为你认为事情是在包里的,而实际上它们并不在包里。这看起来非常合理。当我编写C++时,除了最上面的模块外,我总是使用完整的范围(即:Boo::SMALTELTEXPTR,STD::String)。我认为在Ada中采用这样的策略也是有意义的。您使用的是什么编译器?我得到“viterbi.adb:1:31:保留字”和“不能用作标识符”!我正在为Linux x86_64使用GNAT。我现在不在工作,所以我不知道版本号。但是去年秋天我从Libre网站上下载了它。很好,我不知道你可以用逗号分隔包名。这些天我真的需要抽出时间来阅读语言规范。。。