2015-09-05 120 views
3

我有一个Employee包和一个Office包,比方说。 Office包具有一组Employee对象。我可以声明数组,这样将数组初始化为空对象

officeArray : Office.Vector(1..20); 

但我怎么初始化officeArray一组20个空的对象?我试过

officeArray := (others => null); 

这是行不通的。编译器说它需要Employee对象。我可以创建一个虚拟Employee对象来填充数组,或者有另一种方法来完成此操作吗?

+0

它是一个访问类型的数组还是不是? –

+0

如果您向我们展示了 - 至少 - “Office.Vector”的声明,我们将能够更好地为您提供帮助。 –

+0

和'员工'的声明。无论这种声明是什么,你必须为自己定义一个'员工'是什么意思是“空”的员工。假设'Employee'是一条记录,那么该记录的“null”值就没有内置的定义,不仅仅是一个“null”Integer的内置定义。 – ajb

回答

4

这里的一个示例程序:

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)数组的元素类型必须是接入类型。