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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.