1 struct A 2 { 3 virtual void f() {tcout << _T("A::f()\n");} 4 }; 5 6 struct B : public A 7 { 8 void f() {tcout << _T("B::f()\n");} 9 }; 10 11 struct C : public B 12 { 13 void f() {tcout << _T("C::f()\n");} 14 }; 15 16 struct D : public C 17 { 18 void f() {tcout << _T("D::f()\n");} 19 }; 20 21 22 int _tmain(int argc, TCHAR * argv[], TCHAR * envp[]) 23 { 24 A * pA = new D; 25 pA->f(); 26 27 return 0; 28 }
结果:D::f()
时间: 2024-10-25 18:01:06