Next: Adding
RTTI to Up: RTTI
Support for Previous: RTTI
Support for
RTTI Basic Tools
In the following, RTTI-class stands for a C++ class which has
RTTI capabilities, p for a pointer to a RTTI-class and T
for a C++ RTTI-class. The 'return type' of a macro stands for the type
of object that macro expands to.
- typeid STATIC_TYPE_INFO(T): Returns a typeid encoding the type
of the C++ RTTI-class T. If T is not a RTTI-class, a compile-time
error occurs.
- typeid TYPE_INFO(p): Returns the typeid for the object p
is pointing at (regardless of p's own type). If p is not
pointing at an object of a RTTI-class, a compile-time error occurs. If
p is NULL, a special typeid for the NULL pointer is returned.
- T* PTR_CAST(T,p): Returns the value of pointer p cast
to the type T, i.e. a T* or NULL if cast fails. If either
*p or T are not RTTI-classes, a compile-time error occurs.
- int typeid::operator==(typeid): Compares two typeids and returns
1 if they represent the same type, else 0. An operator!= with the natural
semantics is also provided for typeids.
- const char* typeid::getname(): Returns the textual name of a
typeid.
- T* TYPE_NEW(T,typeid t): Given a C++ base type T, an
object of type t, where t represents a type identical to
or derived from T, is created and returned as a T*. If T
is not a RTTI-class a compile-time error occurs. If t is not a type
derived from T or not an instantiable type having a default constructor,
NULL is returned. The implicit reasons for needing to supply the type T
of a baseclass of t are described in detail in Section 5.2.6.
Alexandru Telea