Ada Programming/Attributes/'Tag

From Wikibooks, open books for an open world
Jump to: navigation, search

Ada Lovelace 1838.jpg


X'Tag is an Ada attribute where X is any tagged type. This attribute returns a value of the private type Ada.Tags.Tag which identifies the tagged type.

This attribute is useful to check for membership of a type in a class hierarchy. It can also be used if it is known the type is in a class hierarchy and type-specific processing must take place.


Ref : My_Tagged_Type_Reference;
if Ref.All in My_Tagged_Type'Class then
  -- Type is in class hierarchy that contains My_Tagged_Type.
  if Ref.All'Tag = My_Tagged_Type'Tag then
    -- Object is of type My_Tagged_Type.
    -- Object is of some other type in the hierarchy.
  -- Object is not in the class hierarchy
end if;

See also[edit]


Ada Reference Manual[edit]