#include
#include
#include
using namespace std;
class demo
{
private:
virtual void print()
{
cout << "sss" << endl;
}
virtual void print2()
{
cout << "sss" << endl;
}
};
using type = void(*)(void);
int main( In int argc, In_reads(argc) Pre_z char** argv, In_z char** envp )
{
demo a1;
auto a = (type)*((int*)*(int*)(&a1));
a();
system("pause");
return 0;
}
我的问题是:为什么强制转化为(int*)而不是char*或者别的类型呢?
&a1取得对象的地址,(int*)转换为指针的地址,这个地址中存储的就是虚函数表的地址。 64位系统要用Long, 具体你可以看下面的链接:
http://blog.csdn.net/pi9nc/article/details/11924525
auto a = (type)*((int*)*(int*)(&a1));这行代码你看看吧
你这行代码类型是int