C++之对象数组

#include <iostream>


using namespace std;


struct Box
{
public:
Box(int len=10,int w=10,int h=10):length(len),width(w),height(h){}
int volume();
private:
int length;
int width;
int height;
};


int Box::volume()
{
return length*width*height;
}


int main()
{
Box a[2]={Box(),Box(20,20,20)};
cout<<"volime:"<<a[0].volume()<<endl;
cout<<"volime:"<<a[1].volume()<<endl;

return 0;

猜你喜欢

转载自blog.csdn.net/wrc_nb/article/details/80312079