<o:p>C++类模型初探 — </o:p>Stroustrup 《<o:p></o:p>Inside the C++ Object Model》读书笔记
第一章
非静态数据成员直接分配在每个类对象中,而静态数据成员存储在类对象的外面。
静态和非静态的成员函数驻留在类对象的外面,虚函数由下面两步来实现:
- 为每个类生成一个表,表中存储指向各个虚函数的指针
- 每个类对象中插入一个指针,指向上面生成的表。
例如:类Point:
cpp 代码
- class Point {
- public:
- Point (float xval);
- virtual ~Point();
- float x() const;
- static int PointCount();
- protected:
- vitrual ostream& print(ostream &os) const;
- float _x;
- static int _point_count;
- };
根据上面所说的那两点,类Point的内部结构可用下图表示: