// A1b.cpp -- variation b on Question #1 #include class B { public: void mf(int n); protected: int state; }; void B::mf(int n) { cout << " B::mf(" << n << ") invoked\n"; state = n; } class D : public B { public: void mf(int n); }; void D::mf(int n) { cout << " D::mf(" << n << ") invoked\n"; state = -n; } void main() { D d1; // compiler gen'd default ctor for D called // which calls compiler gen'd default ctor for B B *bptr = new D(d1); // memory allocated to hold a D object // on heap, initialized with Compiler // generated copy ctor which calls // compiler generated base void ctor bptr->mf(3); // B:mf is invoked; }