// A2_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; public: virtual void mf() { cout << "\n D::mf()"; } }; void fun(B *pB) { pB[0].mf(); // pB[1].mf(); This statement will cause access violation // if input is an array of derived objects // even though the compiler accepts them with // no warning. } void main() { D da[2]; fun(da); cout << "\n\n"; }