2012-09-02 42 views
3

在最近的一个问题中,我询问了关于'的操作,并了解到它用于获取某些类型的语言定义的“属性”。从我可以收集的信息来看,没有办法为您的类型创建自己的属性。Ada:使用函数重命名属性?

function Image(C: Ada.Containers.Count_Type) return String renames 
      Ada.Containers.Count_Type'Image; 

这是什么做的:

我碰到这行代码,我不明白来的?

+1

有趣相反,有一些情况(重命名-as-body,见http://www.ada-auth.org/standards/12rm/html/RM-8-5-4.html#p5),其中应该是'function Image(C:Ada.Containers .Count_Type'Base)return String'(见http://www.ada-auth.org/standards/12rm/html/RM-K-2.html#p88)。 –

回答

6

某些属性,如“读,”写入“输入与”输出,可以通过用户定义的子程序来覆盖,例如:

procedure My_Write 
    (Stream : not null access Ada.Streams.Root_Stream_Type'Class; 
    Item : in My_Type); 
for My_Type'Write Use My_Write; 

的“图片属性不能被重写。 你例子中的函数定义属性的重命名,让您调用属性就好像它是一个正常的子程序:

Image(My_Count); 

Ada.Containers.Count_Type'Image(My_Count);