【问题标题】:Non-visible declaration in specification file (.ads)规范文件 (.ads) 中的不可见声明
【发布时间】:2019-09-16 21:28:02
【问题描述】:

我不断收到以下错误。我已将违规记录移入和移出包的私有部分,但错误仍然存​​在。我是 Ada 的新手,我在实现这个通用堆栈来保存一组记录时遇到了问题。

我已将记录和类型声明移入和移出私有部分。我还尝试在代码中看到的私有部分之前添加“typegaragebay is private”声明。

-- .ads file --
generic
  low: integer; --lowerbound of stack
  up: integer; -- upperbound of stack
  type item is private; -- type of stack

package gstack is
  type garageBay is private;

  procedure tpush(x: in item);
  procedure tpop(x: out item);
private
  type vehicle is array(1..15) of character;
  type vName is array(1..8) of character;
  type garageBay is record
      vehicleType: vehicle;
      vehicleName: vName;
      time2Fix: integer;
      startTime: integer;
      finishTime: integer;
  end record;
  type entries is array(low..up) of item;
end gstack;
-- driver file
with Ada.Text_IO; use Ada.Text_IO;  -- in file Gusestac.adb
with gstack;  -- generic stack defined in gstack10.ads /.adb
procedure gusestack is
    package IIO is new Ada.Text_IO.Integer_IO(integer); use IIO;
    lowerbound: integer;
    upperbound: integer;
begin
    get(lowerbound);
    get(upperbound);
    declare
      package genericS is new gstack(lowerbound,upperbound, garageBay);
      use genericS;
    begin
      put(""); -- placeholder
    end;
end gusestack;
-- Errors
x86_64-linux-gnu-gcc-8 -c gusestack.adb
gusestack.adb:11:63: "garageBay" is not visible
gusestack.adb:11:63: non-visible declaration at gstack.ads:7
gusestack.adb:11:63: instantiation abandoned
gusestack.adb:12:13: "genericS" is undefined
gnatmake: "gusestack.adb" compilation Error

【问题讨论】:

  • @SimonWright@DeeDee 我尝试更新记录并将其推入堆栈; put("请输入车辆名称:" );得到(车库eBay.vehicleName); tpush(车库易趣);我收到错误“x86_64-linux-gnu-gcc-8 -c gusestack.adb.gusestack.adb:24:21: invalid prefix in selected component "garageBay".gusestack.adb:25:23: invalid use of subtype在表达式或调用中标记。gnatmake: "gusestack.adb" 编译错误。
  • 您似乎认为 Garagebay 是直接可见的。它不是。了解可见性对于了解 Ada 至关重要,因此我建议您在进一步尝试之前了解 Ada 的可见性规则。

标签: generics package ada


【解决方案1】:

您正在尝试使用在通用包gstack 中定义的类型garageBay 来创建gstack 的具体实例。在gstack 的实例化之前,您可能希望将类型定义garageBaygstack 的私有部分移动到gusestack 的声明部分。

【讨论】:

  • 事实上:gstackitems 的通用堆栈,你想用item => garageBay 实例化gstack - 就像我想用item => coffeeBrand 实例化它一样,对于实例。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-09
  • 2017-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-07
相关资源
最近更新 更多