411 REFERENCE · Wikibooks
Ada Programming/Attributes/'Tag
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Attributes 'Tag
__TOC__
Description
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.
Example
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;
See also
Wikibook
Ada Programming
Ada Programming/Object Orientation
Ada Programming/Attributes/'Class
Ada Reference Manual
13 3 Operational and Representation Attributes
K Language-Defined Attributes
Tag