无法创建访问类型来访问整数数组

Can’t create access type to access an array of integer

创建整数数组的访问类型时出错。下面是我的代码,请帮我修复一下。

procedure arry_point is
   type arr is array(1..5) of integer;
   obj:aliased arr;
   type my_access1 is access all arr;
   var1:my_access1:=obj'Access;-- this is good
   ii: aliased array(1..5)of integer
   type my_access is access all ii; --this is bad but how can i create access type for ii ?
   var:my_access:=ii'access;   ---?
begin
   null;
end arry_point;

type My_Access is access ...什么?答案是,它必须是类型名称(严格来说是 subtype_indication,参见 ARM 3.10(3).

当您说 ii: aliased array(1..5) of integer 时,您正在创建一个匿名类型的数组;这意味着您无法提供类型名称来完成访问类型定义。

您可以想象一种语言(C++?),您可以在其中说

type My_Access is access all Type_Of (II);

或者,也许,

type My_Access is access all II'Type;

但在 Ada 中这些都不可能。我怀疑原因是没有任何意义,因为在 Ada 中,即使具有相同的结构,类型也不等价:

 1. procedure SG is
 2.    A : array (1 .. 5) of Integer := (others => 0);
 3.    B : array (1 .. 5) of Integer;
 4. begin
 5.    B := A;
            |
    >>> expected type of B declared at line 3
    >>> found type of A declared at line 2

 6. end SG;