The dynamic_cast<>
operation and typeid
operator in C++ are part of RTTI.
The C++ run-time type information permits performing safe typecasts and manipulate type information at run time.
RTTI is available only for classes which are polymorphic, which means they have at least one virtual method. In practice, this is not a limitation because base classes must have a virtual destructor to allow objects of derived classes to perform proper cleanup if they are deleted from a base pointer.
RTTI is optional with some compilers; the programmer can choose at compile time whether to include the function. There may be a resource cost to making RTTI available even if the program does not use it.