比方说,我有一个员工薪酬和一个办公室薪酬。Office包有一个Employee对象数组。我可以声明数组,以便
officeArray : Office.Vector(1..20);但是如何将officeArray初始化为一组20个空对象呢?我试过了
officeArray := (others => null);这不起作用。编译器说它需要Employee对象。我可以创建一个虚拟的Employee对象来填充数组,或者有其他方法可以做到这一点吗?
发布于 2015-09-06 00:45:24
下面是一个示例程序:
With Ada.Text_IO; Use Ada.Text_IO;
With Ada.Integer_Text_IO; Use Ada.Integer_Text_IO;
procedure Program is
type Employee is record
name : String(1..50);
end record;
type EmployeeArr is array (Positive range <>) of Employee;
type EmployeePtr is access all Employee;
type EmployeePtrArr is array (Positive range <>) of EmployeePtr;
employees1 : EmployeeArr(1..20);
employees2 : EmployeePtrArr(1..20);
begin
employees1 := (others => null); -- this will NOT compile
employees2 := (others => null); -- this compiles fine
end Program;为了分配(others => null),数组的元素类型必须是访问类型。
https://stackoverflow.com/questions/32413026
复制相似问题