即使使用这个简单的例子,我也无法让动态调度工作.我相信问题在于我如何设置类型和方法,但看不到哪里!
with Ada.Text_Io;
procedure Simple is
type Animal_T is abstract tagged null record;
type Cow_T is new Animal_T with record
Dairy : Boolean;
end record;
procedure Go_To_Vet (A : in out Cow_T) is
begin
Ada.Text_Io.Put_Line ("Cow");
end Go_To_Vet;
type Cat_T is new Animal_T with record
Fur : Boolean;
end record;
procedure Go_To_Vet (A : in out Cat_T)
is
begin
Ada.Text_Io.Put_Line ("Cat");
end Go_To_Vet;
A_Cat : Cat_T := (Animal_T with Fur => True);
A_Cow : Cow_T := (Animal_T with Dairy => …Run Code Online (Sandbox Code Playgroud) 有点尴尬地问这个,但我知道这是最好的.我已经在Ada编程多年了,并且能够流利地理解语言的几乎所有部分.但是,我似乎永远无法绕过T'Class.借用别人,有人可以"像我五岁那样解释它吗?".
编辑:我买它只是为了拥有,但包含在内的是T'Class的一个很好的描述和示例使用; 我指的是Michael B. Feldman撰写的"Ada 95的软件构建和数据结构".
ada ×2