我使用John English:Ada95:面向对象编程的工艺作为教程,我目前正处于表达式计算器章节.这意味着用面向对象的方法编写算术表达式计算器.
该程序编译但提出:
mehdi@debian ~/expressions> ./driver
Execution terminated by unhandled exception
raised PROGRAM_ERROR : expressions.adb:4 finalize/adjust raised exception
Call stack traceback locations:
0x408749 0x408aa4 0x401af6 0x4024ee 0x7f05fe7132df 0x401988 0xfffffffffffffffe
Run Code Online (Sandbox Code Playgroud)
从那些有趣的数字我只能提取这些信息:
addr2line --exe=driver 0x408749 0x408aa4 0x401af6 0x4024ee 0x7f690a2b32df 0x401988 0xfffffffffffffffe
/home/mehdi/expressions/pointers.adb:40 (discriminator 6)
/home/mehdi/expressions/expressions.adb:17
/home/mehdi/expressions/driver.adb:8
/home/mehdi/expressions/b__driver.adb:267
??:0
??:?
??:0
Run Code Online (Sandbox Code Playgroud)
上述行,一个接一个:
overriding procedure Adjust (Object: in out Smart_Pointers) is
begin
Object.Node.Count := Object.Node.Count + 1;
end Adjust; -- here FIRST ONE
end Evaluate; -- SECOND
Put_Line("Le résultat de 598-8/84+25*5*(-5/54) est …Run Code Online (Sandbox Code Playgroud) 在Ada中这很简单:
type ITEM_RECORD;
type ITEM_ACCESS is access ITEM_RECORD;
type ITEM_RECORD Is
record
ITEM: item_type;
Next: item_access;
Pred: item_access;
end record;
Run Code Online (Sandbox Code Playgroud)
容易,对吗?现在,如果我想让ITEM_ACCESS成为通用包中声明的智能/安全指针,该怎么办?我直觉地这样做,只要它有效:
type ITEM_access;
type Item_Record is record
Item : Item_Type;
Next : Item_Access;
Pred : Item_Access;
end record;
type pointers_on_record is access Item_record;
package pointers_p is new pointers(Item_Record, pointers_on_record);
type item_access is new pointers_p.Pointer_Type;
Run Code Online (Sandbox Code Playgroud)
通用的规格如下:
generic
type Item_Type(<>) is limited private;
type Access_Type is access Item_Type;
package Pointers is
type Pointer_Type is private;
Run Code Online (Sandbox Code Playgroud)
我还没想出怎么做.
谢谢 !