加等运算符重载

约 0 个字 27 行代码

#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();

}

颜色主题调整

评论区~

有用的话请给我个赞和 star => GitHub stars
快来跟我聊天~