64,637
社区成员
发帖
与我相关
我的任务
分享
class A
{
public:
virtual void vFun();
};
class B:public A
{
public:
virtual void vFun2();
};
class C:public B
{
void vFun2();
};
void A::vFun()
{
cout << "I'm A::vFun()" << endl;
}
void B::vFun2()
{
cout << "I'm B::vFun2()" << endl;
}
void C::vFun2()
{
cout << "I'm C::vFun2()" << endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
B *b = new C();
b->vFun2();//断点处
system("pause");
return 0;
}
int main()
{
C c;
typedef void (*FUN)(); //函数指针
FUN run_crazily = (FUN)(*((int*)*(int*)(&c)+1));
run_crazily();
system("pause");
return 0;
}
楼主试试上面的测试代码就知道了
int main()
{
A *b = new B();
b->vFun2();//会报错的
system("pause");
return 0;
}