【发布时间】: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 的可见性规则。