将记录数据类型压入堆栈

Push a record datatype into a stack

我是 Ada 的新手,我不知道如何更新记录中的字段并将记录推送到用通用包实例化的堆栈中。

我试过使用 genericS.vehicleName 和 garageBay.vehicleName 都无济于事。

--Snippet
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;
begin
get(lowerbound);
get(upperbound);
declare
package genericS is new gstack(lowerbound,upperbound, garageBay);
use genericS;
begin
    put("Enter vehicle name: " ); 
    get(garageBay.vehicleName); 
    tpush(garageBay);
end;

--Errors
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 mark in expression or call
gnatmake: "gusestack.adb" compilation error

您似乎混淆了类型和类型的实例。您定义了 garbageBay 类型,但从未创建该类型的实例。类型声明定义类型的结构,包括类型实例所需的内存量。它不会为一个类型的所有可以想象的实例分配内存。您必须在代码的声明部分创建一个 garbageBay 实例,例如

element : garbageBay;

然后你可以修改你的代码说

get(element.vehicleName);
tpush(element);