#include <iostream> using namespace std; class A { public: virtual void f () { cout << "A::f" << endl; g (); } void g () { cout << "A::g" << endl; } }; class B : public A { public: void f () { cout << "B::f" << endl; } void g () { cout << "B::g" << endl; f (); } }; class C : public B { public: void f () { cout << "C::f" << endl; } void g () { cout << "C::g" << endl; f (); } }; void P ( A * pa, B & b ) { pa->f (); pa->g (); b.f (); b.g (); delete pa; } int main () { B b; P ( new A, b ); cout << "------------------------------" << endl; C c; P ( new B, c ); return 0; }