跳轉到內容

Ada 程式設計/屬性/'Tag

來自華夏公益教科書,自由的教科書

Ada. Time-tested, safe and secure.
Ada. 經時間考驗,安全可靠。

X'Tag 是一個 Ada 屬性,其中 X 是任何 帶標籤型別。此屬性返回私有型別 Ada.Tags.Tag 的值,該值標識帶標籤型別。

此屬性對於檢查型別在類層次結構中的成員資格很有用。如果已知型別位於類層次結構中並且必須進行型別特定的處理,也可以使用它。

Ref : My_Tagged_Type_Reference;
...
if Ref.all in My_Tagged_Type'Class then
  -- The object pointed at by Ref is in class hierarchy that is rooted at My_Tagged_Type.
  if Ref.all'Tag = My_Tagged_Type'Tag then
    -- Object is of type My_Tagged_Type.
  else  
    -- Object is of some other type in the hierarchy.
  end if;
else
  -- Object is not in the class hierarchy rooted at My_Tagged_Type (it might be of a progenitor type though).
end if;

華夏公益教科書

[編輯 | 編輯原始碼]

Ada 參考手冊

[編輯 | 編輯原始碼]
華夏公益教科書