ATL布幔之下的秘密(1)2010-11-22李马介绍在本系列的教程中,我要讨论一些ATL的内部工作方式以及它所 使用的技术。在讨论的开始,让我们先看看一个程序的内存分布。首先 ,编写一个简单的程序,它没有任何的数据成员,你可以看看它的内存结构。程序1.#include <iostream> using namespace std; class Class { }; int main() { Class objClass; cout << "Size of object is = " << sizeof(objClass) << endl; cout << "Address of object is = " << &objClass << endl; return 0; }这个程序的输出为:Size of object is = 1 Address of object is = 0012FF7C现在,如果我 们向类中添加一些数据成员,那么这个类的大小就会是各个成员的大小之和。对 于模板,也依然是这样:程序2.#include <iostream> using namespace std; template <typename T> class CPoint { public: T m_x; T m_y; }; int main() { CPoint<int> objPoint; cout << "Size of object is = " << sizeof(objPoint) << endl; cout << "Address of object is = " << &objPoint << endl; return 0; }现 在程序的输出为:Size of object is = 8 Address of object is = 0012FF78那么,再向程序中添加继承。现在我们使Point3D类继承自 Point类,然后来看看程序的内存结构: