Next: RTTI Basic Tools Up: A General-Purpose Run-Time Type Previous: Uses of Run-Time

RTTI Support for the Application Programmer

 

In this section we describe the effective tools we offer to the application programmer to implement and use RTTI.

A typeid class is introduced to represent the type of a C++ class. Some of the previously presented operations are supported directly by methods of the class typeid (see Section 5.1 for a full description of the typeid class). Some other operations, however, had to be implemented as C++ macros, since they return typed pointers or have type arguments (by type, we mean a C++ class type). As outlined before, C++ does not have 'type variables' which could be passed to or returned from methods, hence the only way to implement such operations was to use macros.

To summarize, the programmer can manipulate type information at run-time by using typeid instances. Such instances can be freely copied, deleted, assigned to and copy constructed, mostly like any 'well-behaving' C++ class instances.

We shall present firstly these methods and macros which support the operations described in Section 3. A simple method to add RTTI capabilities to a C++ class will be then introduced. Finally, we give some examples of how the RTTI system can be used.





Alexandru Telea