class Father { public: virtual void Test() { cout<<"cout Father Test"<<endl; TestB(); } virtual void TestB() { cout<<"cout Father TestB"<<endl; } }; class Son:public Father { public: virtual void TestB() { cout<<"cout Son TestB"<<endl; } }; 调用: Son* pSon=new Son(); pSon->Test(); pSon->TestB(); Father* pFather=(Father*)pSon; pFather->Test(); pFather->TestB();
结果:
cout<<"cout Son TestB"<<endl;
cout<<"cout Son TestB"<<endl;
cout<<"cout Son TestB"<<endl;
cout<<"cout Son TestB"<<endl;
总结:子类重新实例化虚函数,所以在实际的过程中,所以虚函数表记录的
肯定不是父类的函数,而是子类的函数过程。
原文地址:http://5228690.blog.51cto.com/5218690/1627603