包不可见错误

发布于 2024-10-15 17:18:24 字数 952 浏览 3 评论 0原文

我在包可见性方面遇到了麻烦。我有一个非常简单的包,代码如下所示。错误消息如下所示:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我早已燃尽 2024-10-22 17:18:24

提供的包体代码存在语法错误:“use with Ada.Integer_Text_IO;”中的虚假“with”条款。

修复此问题后,我收到了围绕无法解析 File_TypeOpenClose 的编译错误。添加 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
   ...

如果修复这些错误后仍然出现“找不到 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:

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
   ...

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?

往事风中埋 2024-10-22 17:18:24

正如已经指出的,通过使用逗号分隔样式,您可以避免“use with”样式的错误:

-- 测试,
Ada.Integer_Text_IO,
艾达.字符串;

Use
-- Testing,
Ada.Strings,
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;

Use
-- Testing,
Ada.Strings,
Ada.Integer_Text_IO;

this also allows you to comment out specific package 'withs' or 'usues' as shown.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文