加等运算符重载
约 0 个字 27 行代码 预计阅读时间不到 1 分钟
#include <iostream>
using namespace std;
class Complex{
private:
float x,y;
public:
Complex(float x = 0,float y = 0)
{
this->x = x;
this->y = y;
}
void dis(){
cout <<x << " ," << y << endl;
}
Complex & operator+=(const Complex &c){
this->x += c.x;
this->y += c.y;
return *this;
}
};
int main(){
Complex a(10,20),b(20,10);
a+=b+=a; //从右往左
a.dis();
}