Jump to content

C++ Language/Objects/Inheritance/PolymorphismSyntax

From Wikibooks, open books for an open world

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.

Additional information about polymorphism syntax