classA { private: int a = 1; public: voidf1(int x){ std::cout << "this is class A, f1 " << x << std::endl; } virtualvoidf2(){ std::cout << "this is class A, f2" << std::endl; } }; classB : public A{ private: int b = 2; public: voidf1(int x){ std::cout << "this is class B, f1 " << x << std::endl; } voidf2(){ std::cout << "this is class B, f2" << std::endl; f1(10); } }; classC : public B{ private: int c = 3; public: voidf1(int x){ std::cout << "this is class C, f1 " << x << std::endl; } voidf2(){ std::cout << "this is class C, f2" << std::endl; f1(10); } };
intmain(){ A* pa = new C; pa->f2(); delete pa; return0; }