C++ Language/Objects/Inheritance/PolymorphismSyntax
Frequently, an object is allocated by instantiating the derived class, but "pointed-at" by a pointer variable whose type is "pointer-to-base-class": CRBase* poBase = (CRBase*)(new CRDerived);
.
If CRBase
and CRDerived
have provided two different implementations of the same DoAction()
member function, then poBase->DoAction()
would call the base class' implementation.
But if the member function had been marked by the virtual
keyword, then poBase->DoAction()
would instead "polymorphically" call the derived class' implementation.