RTTI

A better solution has recently been added to C++. the RTTI, or run-time typing information system, allows a form of cast that will be checked at run-time. The dynamic cast operator either performs the cast, or returns a null value if the transformation is not valid. This latter condition can then be tested by a subsequent if statement.

This is safe, but the dynamic cast operator is only useable if the parent class has defined at least one virtual method.

[audio] [real] Text to accompany slide22, in Chapter 12 of An Introduction to Object-Oriented Programming