1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| #include<bits/stdc++.h> using namespace std; class Base{ public: virtual void f(){cout<<"Base:f"<<endl;} virtual void g(){cout<<"Base:g"<<endl;} virtual void h(){cout<<"Base:h"<<endl;} };
typedef void(*Fun)(void); A Base b; Fun pFun = NULL;
int main(){ cout << "虚函数表地址:" << (int*)(&b) << endl;
cout << "虚函数表 — 第一个函数地址:" << (int*)*(int*)(&b) << endl; pFun = (Fun)*((int*)*(int*)(&b));
pFun();
return 0; }
|
子类覆盖父类 https://blog.csdn.net/weixin_40237626/article/details/82313339