流沙团
测试C++虚函数表
2017-11-29 流沙团
// 20171122_01.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "windows.h"
#include "stdlib.h"
#include "iostream.h"
#include <stdio.h>

struct Base{
int a;
int b;

virtual void Fn1()
{
printf("1111\n");
}

virtual void Fn2()
{
printf("2222\n");
}
};

void TestMethod()
{
Base base;
printf("虚表的地址:%x \n",*((int*)(&base)));
//定义函数指针
typedef void(*pFunction)(void);
pFunction pFn;
int Temp = *((int*)(&base));
pFn = (pFunction)(*((int*)(Temp)));
pFn();
pFn = (pFunction)(*((int*)(Temp)+1));
pFn();
}

int main(int argc, char* argv[])
{


TestMethod();

return 0;
}
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容