#include<iostream>
using namespace std;
class rectangle
{
public:
rectangle()
{
cout<<"构造一个长方形a!"<<endl;
}
rectangle(int l,int w)
{
length=l;width=w;
cout<<"长方形的面积为"<<length*width<<endl;
}
rectangle(int l,int w,int h)
{
length=l;width=w;height=h;
cout<<"长方体的体积为"<<length*width*height<<endl;
}
int area(){return length*width;}
private:
int length;
int width;
int height;
};
int main()
{
rectangle a;
rectangle b(3,4);
rectangle c(3,4,10);
return 0;
}
【c++程序】重载构造函数(示例)
最新推荐文章于 2023-06-11 20:37:15 发布