next up previous index
Next: RTTI Operation: Type Up: The Type_info Class Previous: The Type_info Class

RTTI Operation: Retrieving Type Information From Classes and Pointers

The first operation we need is to get a Type_info from a C++ class pointer or a C++ class. As already explained in the previous section, the Type_info is a static member called, for example, of the C++ class. Given a C++ class T as argument, the STATIC_TYPE_INFO macro will simply retrieve the RTTI_obj member of T. Given a C++ class pointer p (which, say, points to an actual T object), the TYPE_INFO macro will call a virtual method via p which will return the same RTTI_obj object (Figure 2.

  
Figure 2: Retrieving Type_info from C++ pointers. The TYPE_INFO macro calls a virtual function of the pointed object which returns the static Type_info class member of its class.

In order to do this, we need to add a static Type_info member and a virtual method to each C++ class T which wishes to use RTTI operations.



Alexandru Telea