// 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; }
0则评论给“测试C++虚函数表”