// B6.cpp - Question #6 #include class B { public: virtual 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 for D called // which calls compiler gen'd void ctor for B D da[3] = { d1, d1, d1 }; // compiler gen'd copy ctor for D called which // calls compiler gen'd void ctor for B da[0].mf(3); // D object in da[0] invokes its mf }