构造函数的重载

来源:互联网 发布:串口通信编程 编辑:程序博客网 时间:2024/06/04 18:43
#include<iostream>using namespace std;class Box{public:Box();Box(int h,int w,int len):height(h),width(w),length(len) {}int  volume();private:int height;int width;int length;};Box::Box(){height=10;width=10;length=10;}int  Box::volume(){return(height*width*length);}int main(){Box Box1,Box2(15,30,25);cout<<"The volume of the box1 is"<<Box1.volume()<<endl;    cout<<"The volume of the box2 is"<<Box2.volume()<<endl;return 0;}