Dynamic_cast
dynamic_cast is a C++ run-time checked cast that converts pointers or references within an inheritance hierarchy and safely indicates incompatible conversions.
Object-Oriented Software Design in C++
dynamic_cast is a C++ run-time checked cast that converts pointers or references within an inheritance hierarchy and can fail safely for incompatible types.
- How it is used
- Uses run-time type checks to select matching subclasses while searching a heterogeneous catalogue of books.
- How deep it goes
- Explains pointer checking and conversion through a catalogue example, then stops at the resulting design complexity.
- Examples
- Uses Book, Fiction, Cookbook, Attributes, FictionAttrs, and Catalogue::find as concrete pointer-casting examples.
- What you can do after
- Evaluate and understand safe subclass selection while recognizing the coupling and change leaks introduced by repeated casts.
Read how Object-Oriented Software Design in C++ explains dynamic_cast →
100 C++ Mistakes and How to Avoid Them
dynamic_cast is a C++ run-time checked cast expression for converting within polymorphic class hierarchies or testing such conversions.
- How it is used
- Checks whether a base-class pointer or reference can safely represent a specified derived type at run time.
- How deep it goes
- Explains polymorphic prerequisites, pointer null results, reference exceptions, and runtime failure consequences.
- Examples
- Uses B and D classes, a base pointer, a checked downcast, and incompatible-downcast handling.
- What you can do after
- Apply dynamic_cast with pointer-result checks and recognize when polymorphic redesign is safer.
Read how 100 C++ Mistakes and How to Avoid Them explains dynamic_cast →
Related concepts
- downcastingaddresses · Downcasting is converting a value from a general type to a more specific compatible type, typically subject to runtime validation.
- static_castcontrasts with · static_cast is a C++ explicit conversion expression that performs compile-time-checked conversions between specified, related, or otherwise compatible types.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

