c++ 对象模型(二)
来源:互联网 发布:seo自学好学吗 编辑:程序博客网 时间:2024/05/20 20:58
《c++ 对象模型》讲到了,对于虚函数表指针的分布,直接截书中的图
先上代码
struct no_virts{int d1;int d2;};class has_virts : public no_virts{public:int d3;virtual void foo() { printf("--- has_virts foo \n"); } };void testMemObj(){has_virts hv;hv.d1 = 111;hv.d2 = 222;hv.d3 = 333;//无论虚函数放在对象的哪个位置,对象中的虚函数表都是位于对象内存分布的顶端Fun pFunc = (Fun)*((int*)(*((int*)(&hv) + 0)) + 0); //foo方法 pFunc();int d1 = (int)*((int*)(&hv) + 1); //111printf("--- d1:%d\n", d1);int d2 = (int)*((int*)(&hv) + 2); //222printf("--- d2:%d\n", d2);int d3 = (int)*((int*)(&hv) + 3); //333printf("--- d3:%d\n", d3);}
0 0
- C++对象模型(二)
- c++ 对象模型(二)
- C++ 对象模型(二)
- GIS Geometry对象模型 (二)
- GIS面向对象模型设计(二)
- C++对象模型(二)多继承
- DHTML对象模型 (二)
- C++对象模型(二)
- [C++]函数对象(二)
- Objective-C对象模型
- Objective-C对象模型
- objective C 对象模型
- C ++ 对象模型
- Objective-C 对象模型
- 【C++】对象模型
- Objective-C对象模型
- java存储模型与C语言存储模型(二)
- 《深度探索C++对象模型》(二)C++,new,delete,构造/析构,临时对象
- matlab 图像处理
- 响应式布局
- 内存对齐
- LeetCode -- LRU Cache
- 在Eclipse中搭建ArcGIS API for JavaScript 3.9 开发环境
- c++ 对象模型(二)
- iOS 开发导航栏使用系统自定义属性基本4条
- linux 下 FTP 配置文件详解
- WebView相关
- ABB 机器人 压包指令PackRawBytes 解包指令UnpackRawBytes
- Codeforces Round #332 (Div. 2)A. Patrick and Shopping(简单题)
- Android 开发如何做好内存优化
- php发邮件
- 聊天室软件设计-nodejs