#include<iostream>
using namespace std;
// 重载前置++ 前置-- 运算符
class Complex {
private:
int a;
int b;
friend Complex& operator++(Complex& c1);
public:
Complex(int a, int b) {
this->a = a;
this->b = b;
}
void Print() {
cout << this->a << " + " << this->b <<"i" <<endl;
}
//重载前置 --
Complex& operator--() {
this->a--;
this->b--;
return *this;
}
};
// 全局函数 重载前置++
Complex &operator++(Complex& c1) {
c1.a++;
c1.b++;
return c1;
}
int main() {
Complex c1(1, 2), c2(3, 4);
// 重载前置++ (通过全局函数)
++c1;
c1.Print();
//重载前置-- (通过成员函数)
--c2;
c2.Print();
system("pause");
}