虚函数表中除了正常函数指针,还有其他的指针
2009-09-11 17:51
281 查看
#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 1st entry = " << (int*)*((int*)*(int*)this+0) << endl; cout << "Value at Vtable 2nd entry = " << (int*)*((int*)*(int*)this+1) << endl; cout << "Value at Vtable 3rd entry = " << (int*)*((int*)*(int*)this+2) << endl; cout << endl; } virtual void f1() { cout << "Base::f1" << endl; } virtual void f2() { cout << "Base::f2" << 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 1st entry = " << (int*)*((int*)*(int*)this+0) << endl; cout << "Value at Vtable 2nd entry = " << (int*)*((int*)*(int*)this+1) << endl; cout << "Value at Vtable 3rd entry = " << (int*)*((int*)*(int*)this+2) << endl; cout << endl; } virtual void f1() { cout << "Drive::f1" << endl; } }; int main() { Drive d; return 0; }
运行结果
In Base Virtual Pointer = 0012FF7C Address of Vtable = 0046C0E0 Value at Vtable 1st entry = 004010F0 Value at Vtable 2nd entry = 00401145 Value at Vtable 3rd entry = 00000000 In Drive Virtual Pointer = 0012FF7C Address of Vtable = 0046C0C8 Value at Vtable 1st entry = 0040121C Value at Vtable 2nd entry = 00401145 Value at Vtable 3rd entry = 00000000
相关文章推荐
- 除了修改WEBCONFIG会导致WEB服务重启外,还有其他的什么操作会导致重启?
- FileReader除了有函数readAsDataURL,另外还有另外两个函数readAsBinaryString 和 readAsText,分别可以将选择的文件读取成二进制和文本格式
- 结构和其他数据形式 函数和指针
- 类的成员函数指针作为参数传递给其他函数和普通函数指针的传递是不同的
- 函数内空指针调用其他函数赋值
- 网页上有错误,除了js,还有其他原因【原】
- C++ MFC 其他函数获得主对话框指针并使用成员的方法
- C语言关于数组、指针、函数和结构体的其他知识
- C++ MFC 其他函数获得主对话框指针并使用成员的方法
- 循环调用修正sic86 2改后的(除了第一年有点诡异,其他年份可以正常修复)
- 第14章 结构和其他数据形式 14.14 函数和指针
- 关于AggregationClient 除了rowCount以外的其他聚合函数抛空指针异常的解释
- 实验 9 指针1 输入一行字符,要求用自定义的函数void f(char *line)统计和输出字符串中数字字符、英文字符和其他字符的个数
- 云端办公?除了访问不了的谷歌和付费的微软,您其实还有其他选择
- 函数指针玩得不熟,就不要自称为C语言高手(函数指针是解耦对象关系的最佳利器,还有signal)
- 除了SLEEP还有没有更高精度的函数啊?
- SQL SERVER四舍五入你除了用ROUND还有其他方法吗?
- 类的成员函数指针作为参数传递给其他函数和普通函数指针的传递是不同的
- 第五周 阅读程序 在 main 函数中,可设置指向对象public 成员、对象函数还有对象的指针
- 这条路不同于其他的路,或者说这是一条简单的小路,幽深的小路。路的两边稀稀拉拉栽着几棵残树,或许是刚刚过完冬天,原本稀稀拉拉的树枝愈发疲惫。除了残树,还有一些灌木丛,深绿显得有些褐色...