//使用有默认参数的构造函数
#include<iostream>
using namespace std;
class Box
{
public:
Box(int h=10,int w=10,int len=10);
int v();
private:
int height;
int width;
int length;
};
Box::Box(int h,int w,int len)
{
height=h;
width=w;
length=len;
}
int Box::v()
{
return(height*width*length);
}
int main()
{
Box box4;//要注意此处无()
cout<<"gd"<<box4.v()<<endl;
Box box1(13);
cout<<box1.v()<<endl;
Box box2(12,23);
cout<<"hjgj"<<box2.v()<<endl;
Box box3(12,34,1);
cout<<"HJGjg"<<box3.v()<<endl;
return 0;
}
默认构造函数
最新推荐文章于 2024-07-18 15:39:03 发布