
- #include
-
- using namespace std;
-
-
- class Person
- {
- friend Person &operator-=(Person &L,const Person &R);
- friend bool operator<(const Person &L, const Person &R);
- friend const Person operator-(const Person &L, const Person &R);
- friend const Person operator+(const Person &L, const Person &R);
- friend bool operator>(const Person &L, const Person &R);
- friend Person &operator+=(Person &L,const Person &R);
- private:
- int a;
- int b;
- public:
- Person(){}
- Person(int a, int b):a(a),b(b)
- {}
-
- //成员函数实现+号运算符重载
- // const Person operator+(const Person &p) const
- // {
- // Person temp;
- // temp.a = a + p.a;
- // temp.b = b + p.b;
- // return temp;
- // }
-
- //成员函数实现-号运算符重载
- // const Person operator-(const Person &p) const
- // {
- // Person temp;
- // temp.a = a - p.a;
- // temp.b = b - p.b;
- // return temp;
- // }
-
- //成员函数实现*号运算符重载
- // const Person operator*(const Person &p) const
- // {
- // Person temp;
- // temp.a = a * p.a;
- // temp.b = b * p.b;
- // return temp;
- // }
-
- //成员函数实现/号运算符重载
- // const Person operator/(const Person &p) const
- // {
- // if(p.a!=0&&p.b!=0)
- // {Person temp;
- // temp.a = a /p.a;
- // temp.b = b / p.b;
- // return temp;}
- // else
- // cout<< "除数为0,fault"<< endl;
- // return *this;
- //
- // }
-
- //成员函数实现%号运算符重载
- // const Person operator%(const Person &p) const
- // {
- // Person temp;
- // temp.a = a % p.a;
- // temp.b = b % p.b;
- // return temp;
- // }
-
-
- //成员函数实现>号运算符重载
- // bool operator>(const Person &R) const
- // {
- // if(a>R.a && b>R.b)
- // {
- // return true;
- // }
- // else
- // {
- // return false;
- // }
- // }
-
- //成员函数实现<号运算符重载
- // bool operator<(const Person &R) const
- // {
- // if(a
- // {
- // return true;
- // }
- // else
- // {
- // return false;
- // }
- // }
-
- //成员函数实现==号运算符重载
- // bool operator==(const Person &R) const
- // {
- // if(a==R.a && b==R.b)
- // {
- // return true;
- // }
- // else
- // {
- // return false;
- // }
- // }
-
- //成员函数实现!=号运算符重载
- // bool operator!=(const Person &R) const
- // {
- // if(a!=R.a && b!=R.b)
- // {
- // return true;
- // }
- // else
- // {
- // return false;
- // }
- // }
-
-
- //成员函数实现+=号运算符重载
- // Person &operator+=(const Person &R)
- // {
- // a += R.a;
- // b += R.b;
-
-
- // return *this;
-
-
- // }
-
- //成员函数实现-=号运算符重载
- // Person &operator-=(const Person &R)
- // {
- // a -= R.a;
- // b -= R.b;
-
-
- // return *this;
-
-
- // }
-
- //成员函数实现*=号运算符重载
- // Person &operator*=(const Person &R)
- // {
- // a *= R.a;
- // b *= R.b;
-
-
- // return *this;
-
-
- // }
-
- //成员函数实现/=号运算符重载
- // Person &operator/=(const Person &R)
- // {
- // a /= R.a;
- // b /= R.b;
-
-
- // return *this;
-
-
- // }
-
- //成员函数实现%=号运算符重载
- // Person &operator%=(const Person &R)
- // {
- // a %= R.a;
- // b %= R.b;
-
-
- // return *this;
-
-
- // }
-
-
-
- void show()
- {
- cout << " a = " << a << " b = " << b << endl;
- }
- };
-
-
- //全局函数实现+运算符重载
- const Person operator+(const Person &L, const Person &R)
- {
- Person temp;
- temp.a = L.a + R.a;
- temp.b = L.b + R.b;
- return temp;
- }
-
- //全局函数实现-运算符重载
- const Person operator-(const Person &L, const Person &R)
- {
- Person temp;
- temp.a = L.a - R.a;
- temp.b = L.b - R.b;
- return temp;
- }
-
-
- //全局函数实现>号运算符重载
- bool operator>(const Person &L, const Person &R)
- {
- if(L.a>R.a && L.b>R.b)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
- //全局函数实现<号运算符重载
- bool operator<(const Person &L, const Person &R)
- {
- if(L.a
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
-
- //全局函数实现+=号运算符重载
- Person &operator+=(Person &L,const Person &R)
- {
- L.a += R.a; // a = a + R.a
- L.b += R.b;
-
-
- return L;
-
-
- }
-
- //全局函数实现-=号运算符重载
- Person &operator-=(Person &L,const Person &R)
- {
- L.a -= R.a; // a = a + R.a
- L.b -= R.b;
-
-
- return L;
-
-
- }
-
-
- int main()
- {
-
- return 0;
- }