此Ada2012计划中的错误是什么?
with Ada.Iterator_Interfaces;
package My is
type Cursor is private;
function Has_Element (Position: Cursor) return Boolean;
package Base_Iterators is new Ada.Iterator_Interfaces(Cursor, Has_Element);
type Bindings_Iterator is new Base_Iterators.Forward_Iterator with private;
overriding function First (Object: Bindings_Iterator) return Cursor;
overriding function Next (Object: Bindings_Iterator; Position: Cursor) return Cursor;
private
type Iterated_Object is access all Integer;
type Cursor is new Iterated_Object;
type Bindings_Iterator is new Base_Iterators.Forward_Iterator with null record;
end My;
尝试检查语法和语义:
$ gnatgcc -gnat2012 -c my.ads
my.ads:23:09: type must be declared abstract or "First" overridden
my.ads:23:09: "First" has been inherited from subprogram at a-iteint.ads:26, instance at line 9
据我所知,First
被我覆盖了。我没有得到编译器投诉的内容。
答案 0 :(得分:2)
错误来自Cursor
是一种私有派生的访问类型。将其更改为
type Cursor is access all Integer;
删除错误,将其更改为记录类型或数字类型。
将Iterated_Object
和Cursor
的完整定义移至公共视图也会删除错误。
我认为你偶然发现了编译器错误。