扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:李马编译 来源:VCKBASE 2007年10月19日
关键字:
#include <iostream> using namespace std; class Base { public: Base() { cout << "In Base" << endl; cout << "Virtual Pointer = " << (int*)this << endl; cout << "Address of Vtable = " << (int*)*(int*)this << endl; cout << "Value at Vtable = " << (int*)*(int*)*(int*)this << endl; cout << endl; } virtual void f1() { cout << "Base::f1" << endl; } }; class Drive : public Base { public: Drive() { cout << "In Drive" << endl; cout << "Virtual Pointer = " << (int*)this << endl; cout << "Address of Vtable = " << (int*)*(int*)this << endl; cout << "Value at Vtable = " << (int*)*(int*)*(int*)this << endl; cout << endl; } virtual void f1() { cout << "Drive::f2" << endl; } }; class MostDrive : public Drive { public: MostDrive() { cout << "In MostDrive" << endl; cout << "Virtual Pointer = " << (int*)this << endl; cout << "Address of Vtable = " << (int*)*(int*)this << endl; cout << "Value at Vtable = " << (int*)*(int*)*(int*)this << endl; cout << endl; } virtual void f1() { cout << "MostDrive::f2" << endl; } }; int main() { MostDrive d; return 0; } |
In Base Virtual Pointer = 0012FF7C Address of Vtable = 0046C0A0 Value at Vtable = 004010F5 In Drive Virtual Pointer = 0012FF7C Address of Vtable = 0046C090 Value at Vtable = 00401221 In MostDrive Virtual Pointer = 0012FF7C Address of Vtable = 0046C080 Value at Vtable = 00401186 |
#include <iostream> using namespace std; typedef void(*Fun)(); class Base { public: Base() { cout << "In Base" << endl; cout << "Virtual Pointer = " << (int*)this << endl; cout << "Address of Vtable = " << (int*)*(int*)this << endl; cout << "Value at Vtable = " << (int*)*(int*)*(int*)this << endl; Fun pFun = (Fun)*(int*)*(int*)this; pFun(); cout << endl; } virtual void f1() { cout << "Base::f1" << endl; } }; class Drive : public Base { public: Drive() { cout << "In Drive" << endl; cout << "Virtual Pointer = " << (int*)this << endl; cout << "Address of Vtable = " << (int*)*(int*)this << endl; cout << "Value at Vtable = " << (int*)*(int*)*(int*)this << endl; Fun pFun = (Fun)*(int*)*(int*)this; pFun(); cout << endl; } virtual void f1() { cout << "Drive::f1" << endl; } }; class MostDrive : public Drive { public: MostDrive() { cout << "In MostDrive" << endl; cout << "Virtual Pointer = " << (int*)this << endl; cout << "Address of Vtable = " << (int*)*(int*)this << endl; cout << "Value at Vtable = " << (int*)*(int*)*(int*)this << endl; Fun pFun = (Fun)*(int*)*(int*)this; pFun(); cout << endl; } virtual void f1() { cout << "MostDrive::f1" << endl; } }; int main() { MostDrive d; return 0; } |
In Base Virtual Pointer = 0012FF7C Address of Vtable = 0046C098 Value at Vtable = 004010F5 Base::f1 In Drive Virtual Pointer = 0012FF7C Address of Vtable = 0046C088 Value at Vtable = 00401221 Drive::f1 In MostDrive Virtual Pointer = 0012FF7C Address of Vtable = 0046C078 Value at Vtable = 00401186 MostDrive::f1 |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者