【发布时间】:2017-04-16 05:21:51
【问题描述】:
我对 Ada 很陌生,我想知道为什么我必须编写 Acc.all 或 d.all 来通过指针调用过程。我认为 .all 主要用于记录,因为这样您可以将 .all 记录值设置为等于其他记录值。同时我想知道为什么我在调用函数时不需要这样做。这是我的代码供参考。请忘记 AnimalPKG.Animals(Total, 3,2,1),因为我只是在练习如何导入包。
with AnimalPKG, Ada.Text_IO, Ada.Integer_Text_IO;
use Ada.Text_IO, Ada.Integer_Text_IO;
procedure Main is
procedure thisisaccess is
begin
Put("thisisaccess");
end thisisaccess;
Type accessprocedure is access procedure;
procedure passinfunction(d : accessprocedure) is
begin
d.all;
end passinfunction;
function times5(a : Integer) return Integer is
begin
return a*5;
end times5;
Type times5access is access function(x : Integer) return Integer;
B : times5access := times5'Access;
Acc : accessprocedure;
Acc2 : accessprocedure; //Modification
Total : Integer;
begin
Acc := thisisaccess'Access; //Modification
Acc2 := Acc; //Modification
Acc2.all; //Modification
AnimalPKG.Animals(Total, 3,2,1);
Put(Total);
Acc.all;
passinfunction(Acc);
Put(B(3));
end Main;
【问题讨论】:
标签: function-pointers ada