#include<iostream>
using namespace std;class Shape
{
protected:
double xCoord,yCoord;
public:
Shape(double x,double y):xCoord(x),yCoord(y){}
virtual int area() const {return 0.0;}
};void main()
{
cout<<"数据成员占有的空间:"<<2*sizeof(double)<<endl;
// cout<<"void *:"<<sizeof(void*)<<endl;
cout<<"Shape:"<<sizeof(Shape)<<endl;
}

解决方案 »

  1.   

    我用 p4/win2000/vc6,当两个成员为double时,输出sizeof(shape)为24
    但如果2个成员为int,则输出sizeof(shape)=12应该与编译器的成员数据对齐设置有关,即project setting->C++里的struct member alignment设置,如果指定为4,则按照4字节对齐,等等
      

  2.   

    忘了说结论...也就是说32位机器上vptr仍然是4 bytes,只是编译器对类对象的内存组织方式引起你所说的问题....请拍砖...