Next: RTTI Support for Up: A General-Purpose Run-Time Type Previous: The Concept of

Uses of Run-Time Type Information

 

If we have a means to obtain a typeid from a pointer, reference or class, we can provide a couple of useful operations on typeids:

Operation 1 allows us to compare types at run-time and determine their relationship (e.g. subclass to superclass). Operation 2 maps types to a textual representation which can be necessary if the user desires to be given type information in a readable way. Operation 3 gives the possibility to cast pointers and references at run-time, which is mostly used in the form of downcasts, i.e. casts from a base type to a derived type and gives the possibility to interpret a pointer in a different way. Operation 4 allows a program to postpone the decision of creating new objects until run-time and then create objects from run-time selected types.




Next: RTTI Support for Up: A General-Purpose Run-Time Type Previous: The Concept of



Alexandru Telea