19.2.1. The dynamic_cast Operator
A dynamic_cast
has the following form:
dynamic_cast<type*>(e)dynamic_cast<type&>(e)dynamic_cast<type&&>(e)
In the first case, e must be a valid pointer (§ 2.3.2, p. 52); in the second, e must be an lvalue; and in the third, e must not be an lvalue.
The cast succeeds if the target type is a public base class of the type of the object denoted by e or if the target type is the same as or the const version of that type. Otherwise, the static type of e must have at least one virtual function and the outcome of the cast depends on the dynamic type of the object denoted by e. If that type is the same as the target type, or contains a subobject (§ 15.2.2, p. 597) of the target type, the cast succeeds; otherwise it fails. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access