next up previous index
Next: Examples: Up: RTTI Support for Previous: Additional RTTI Tools

Creating typeids

 

So far, the programmer can retrieve typeids from existing C++ classes or pointers to objects of these classes. There are however situations when the user would like to 'create' a typeid at run-time and treat it as a typeid obtained from a compile-time type. Such a situation can occur if the user of an application wants to supply a 'type name' at run-time and require the creation of an object of that type. We already have presented the TYPE_NEW macro which can create an object given a typeid for the desired type. However, the user can not give such a typeid at run-time since he has no way to access a C++ class to retrieve its typeid.

One solution is to create a new kind of typeid which will be called a dyn_typeid (dyn stands for dynamic). Such a typeid can be created from a textual description of a type name (e.g. a char*) and should be used only for the TYPE_NEW macro, since it doesn't contain actually any information but a textual type name. See Section 4.5 for an example on how to use a dyn_typeid.



Alexandru Telea