#include<iostream> using namespace std; class SizeBox { public: SizeBox(); int totalSize(); private: char* pMaterial; double length; double breadth; double height; }; SizeBox::SizeBox():length(1.0),breadth(1.0),height(1.0),pMaterial("Cardboard") {cout<<endl<<"Default constrcutor called"<<endl; } int SizeBox::totalSize() { return sizeof(length)+sizeof(breadth)+sizeof(height)+sizeof(pMaterial); } int main() { SizeBox box; SizeBox boxes[10]; cout<<endl<<"The data numbers of a box occupy"<<box.totalSize()<<"bytes."; cout<<endl<<"A singal box object occupies"<<sizeof SizeBox<<"bytes."; cout<<endl<<"An array f 10 Box objects occupies"<<sizeof(boxes)<<"bytes." <<endl; return 0; }

评论