#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;
}
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;
}
但如果2个成员为int,则输出sizeof(shape)=12应该与编译器的成员数据对齐设置有关,即project setting->C++里的struct member alignment设置,如果指定为4,则按照4字节对齐,等等