#include <iostream> class c1{ public: virtual void vfunc(){ std::cout << "Calling c1\n";} }; class c2: public c1{ public: virtual void vfunc(){ std::cout << "Calling c2\n";} }; int main() { class c1 *c; class c1 c1_obj; class c2 c2_obj; c = &c1_obj; c->vfunc(); c = &c2_obj; c->vfunc(); return 0; }
___________OUTPUT____________
Calling c1
Calling c2