#include using namespace std; struct X { X(); virtual void foo() { cout << "foo X" << endl; } virtual void bar() { cout << "bar X" << endl; } int x; }; struct Y : public X { Y(); virtual void foo() { cout << "bar Y" << endl; } virtual void bar() { cout << "bar Y" << endl; } int y; }; X::X() { puts("ctor X"); x = 0; } Y::Y() { perror("ctor Y"); y = 0; } int x; int moo(X *px) { px->foo(); px->bar(); x = 0; } int main() { Y y; X *px = &y; moo(px); cout << "sizeof(X)=" << sizeof(X) << endl; cout << "sizeof(Y)=" << sizeof(Y) << endl; }