Const and static grouped
1 answer
If you know for sure that the passed pointer points to an object of the type child
or its subobject, use
static_cast<child const*>(pParent)
Note that this causes undefined (!) Behavior if the above condition is not met, so if there is a possibility that the pointer does not point to an object of the type child
but parent
is polymorphic, use dynamic_cast
with the same syntax. It will return a null pointer if the cast is invalid, defining the latter via RTTI.
0
source to share