Chapter 27. Using Dynamic Casting and Runtime Type Identification

<feature>
  • See how polymorphic objects canl provide runtime type information

  • Use the new C++ casting operators

  • Learn to cast dynamically

  • See how C++ static casting is like C-style casting

</feature>

Getting and Using Runtime Type Information

When working with class hierarchies, it’s sometimes convenient or necessary to create a pointer of one type and convert it later to some other pointer type. You can always safely cast a derived object pointer to a base object pointer because the base class is part of the derived class. You can then use the derived object pointer to call functions from the base class. On the other hand, a base class can sometimes—but not always—be type cast as a pointer ...

Get Practical C++ now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.