#include <iostream.h> class X { public: void g () { cout << 1 << ' '; } virtual void f () { g (); } }; class Y: public X { public: virtual void g () { cout<< 2<< ' '; } void f () { g (); } }; class Z: public Y { public: void g () { cout << 3 << ' '; } void f () { g (); } }; X x; Y y; Z z; X * px = &x; Y * py = &y; Z * pz = &z; void out ( void ) { px->f (); px->g (); py->f (); py->g (); cout << endl; } int main () { out (); px = py; out (); py = pz; out (); return 0; }