创建整数数组的访问类型会产生错误。以下是我的代码,请帮我解决。
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;
答案 0 :(得分:3)
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;