1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include <iostream> class A { public: int x; }; class B : public A { public: int x; }; int main() { A *a = new A(); a->x = 0; std::cout << a->x << "\n"; B *b = new B(); b->x = 1; std::cout << b->x << "\n"; a = b; std::cout << a->x << "\n"; }