64,649
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
class CRect{
int length,
width;
public:
CRect(){};
CRect(int l,int w){
length=l;width=w;} //不要在代码后放后花括号.也不要在前花括号后抵倒写代码.
void disp(){
cout << "The area is: " <<length*width <<endl;} //不要在代码后放后花括号.
CRect operator,(CRect r){
CRect temp;temp.length=r.lengthltemp.width=r.width;
return temp;}
CRect operator+(CRect r){
CRect temp;
temp.length=r.length+length;//与temp.length=r.length+this->length;相同
temp.width=r.width+width;
return temp;
}
};
int main(){
CRect r1(3,3),r2(5,8),r3(2,4);
r1.disp();r2.disp();r3.disp();
r1=(r1,r2+r3,r4);r1.disp();
return 0;}//不要在代码后放后花括号.