// A1a.cpp - 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 void ctor called for D // which calls B's void ctor D *dptr = new D(d1); // memory allocated to hold a D object // on heap, initialized with compiler gen'd // copy constr of d1 which calls compiler gen'd // base void ctor dptr->mf(3); // D::mf(3) invoked } // note: // default constructor can be called with no args, // e.g., can be used as void ctor // Stroustrup, pg 243