dynamic_cast with Example

dynamic_cast<type> (expr):

The dynamic_cast performs a runtime cast that verifies the validity of the cast. If the cast cannot be made, the cast fails and the expression evaluates to null. A dynamic_cast performs casts on polymorphic types and can cast a A* pointer into a B* pointer only if the object being pointed to actually is a B object

Syntax:

For example:

Output:

Recommended Tutorials: