加上
但是定义一个类的对象的时候就要传入值。如Box box1(10,10,10);
程序代码:
Box(int h,int w,int l):height(h),width(w),length(l){} 是可以的。但是定义一个类的对象的时候就要传入值。如Box box1(10,10,10);
程序代码:
#include <iostream>
using namespace std;
class Box
{
public:
Box(int h,int w,int l):height(h),width(w),length(l){}
// void get_value();
int display();
private:
int height;
int width;
int length;
};
/*void Box::get_value()
{
cin>>height;
cin>>width;
cin>>length;
}
*/
int Box::display()
{
return (height*width*length);
}
int main()
{
Box box1(10,10,10);
// box1.get_value();
cout<<box1.display()<<endl;
return 0;
}

