2012-09-02 108 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);