#include<iostream>
using namespace std;
class box
{
public:
box(int a , int b = 1, int c = 1);
int he();
private:
int h, w, len;
};
box::box(int a,int b,int c) {
h = a;
w = b;
len = c;
}
int box::he()
{
int sum = h * w * len;
return sum
;
}
int main() {
box box1[3] = {
box(10,20,30),
box(3,2,3),
box(102,202,302)//没有","
//调用构造函数box 提供3个元素的实参;
};
for (int i = 0; i < 3; i++)
{
cout << box1[i].he() << endl;
}
return 0;
}
注意这里的写法:
box box1[3] = {
box(10,20,30),
box(3,2,3),
box(102,202,302)//没有","
//调用构造函数box 提供3个元素的实参;
box1[1](1,2,3)的写法不对!