对象数组的使用
#include <iostream>
using namespace std;
class Box
{
public:
Box(int h = 10,int w = 12,int len = 15):height(h),width(w),length(len){};
//等于以下赋值情况
/** height=h;
width = w;
length = len;*/
int volume();
private:
int height;
int width;
int length;
};
int Box::volume(){
return (height*width*length);
}
int main()
{
//定义对象数组,
Box a[3]={
Box(1,2,3), Box(2,3,4),Box(4,5,6)};
cout<<a[0].volume()<<endl;
return 0;
}

浙公网安备 33010602011771号