liveBook · Manning

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.

How 2 Manning books explain it

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 run-time conversions from base-class pointers or references to derived-class types.
How deep it goes
Explains pointer and reference failure results, but not run-time implementation details.
Examples
Shows a B pointer downcast to D and a null check before use.
What you can do after
Diagnose incompatible pointer downcasts by checking whether the result is null.

Read how 100 C++ Mistakes and How to Avoid Them explains dynamic_cast →

What to know first

Related concepts

Questions about dynamic_cast

What is 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.

Which Manning books explain dynamic_cast?

Object-Oriented Software Design in C++ and 100 C++ Mistakes and How to Avoid Them.

What should I know before learning dynamic_cast?

Manning books that teach dynamic_cast usually introduce inheritance first.

What is the difference between dynamic_cast and static_cast?

dynamic_cast is a C++ run-time checked cast that converts pointers or references within an inheritance hierarchy and safely indicates incompatible conversions. 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.