Example of a Dynamic Cast
student s;
account* pa = &s;
student* ps;
ps = dynamic_cast<student*>(pa); //result is valid
savings i;
pa = &i;
ps = dynamic_cast<student*>(pa); //result is a zero
The dynamic_cast operator relies on the dynamic type
information stored in the object pointed to.
Unlike static_cast, the dynamic_cast operator provides a
safe downcast mechanism by returning a zero pointer if
the object pointed to is not in the hierarchy of the type
being cast to.
If it is, a valid pointer is returned.