October 2011
Beginner to intermediate
1200 pages
35h 33m
English
C++ has three components supporting RTTI:
• The dynamic_cast operator generates a pointer to a derived type from a pointer to a base type, if possible. Otherwise, the operator returns 0, the null pointer.
• The typeid operator returns a value identifying the exact type of an object.
• A type_info structure holds information about a particular type.
You can use RTTI only with a class hierarchy that has virtual functions. The reason for this is that these are the only class hierarchies for which you should be assigning the addresses of derived objects to base-class pointers.
Caution
RTTI works only for classes that have virtual functions.
Let’s examine the three components of RTTI.
dynamic_cast OperatorThe dynamic_cast ...
Read now
Unlock full access