Thinking in C++ Vol 2 - Practical Programming |
Prev |
Home |
Next |
Runtime type identification (RTTI)
lets you find the dynamic type of an object when you have only a pointer or a
reference to the base type.
This can be thought of as a secondary feature in C++, pragmatism
to help out when you get into rare difficult situations. Normally, you ll want
to intentionally ignore the exact type of an object and let the virtual
function mechanism implement the correct behavior for that type. On occasion,
however, it s useful to know the exact runtime (that is, most derived)
type of an object for which you only have a base pointer. With this information,
you may perform a special-case operation more efficiently or prevent a
base-class interface from becoming ungainly. It happens enough that most class
libraries contain virtual functions to produce runtime type information. When
exception handling was added to C++, that feature required information about
the runtime type of objects, so it became an easy next step to build in access
to that information. This chapter explains what RTTI is for and how to use it.
Thinking in C++ Vol 2 - Practical Programming |
Prev |
Home |
Next |