// A1_1.cpp #include using namespace std; class B { int x; // data members needed to show the // indexing error, e.g., class objects // need to be different sizes public: virtual ~B() {} virtual void mf() { cout << "\n B::mf()"; } }; class D : public B { int y; virtual void mf() { cout << "\n D::mf()"; } }; void main() { { B *pB = new D[2]; pB->mf(); // (pB+1)->mf(); // this causes an exception // not pointing to beginning // of second object } // memory leak here, pB never deleted cout << "\n\n"; }