关于构造函数应用举例,请半我看看程序中那错了
#include <iostream>using namespace std;
class Box
{
public:
Box(int,int,int);
int volume();
private:
int height;
int width;
int length;
};
Box::Box(int h,int w,int len):height(h),width(w),length(len){}
int Box::volume()
{return(height*width*length);
}
int main()
{Box box1(4,5,6);
cout<<"the volume of box1 is "<<box1.volume<<endl;
return 0;
}