#include <iostream>
using namespace std;
class Person
{
friend const Person operator-(const 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 &R) const
{
Person temp;
temp.a = a+R.a;
temp.b = b+R.b;
return temp;
}
void show()
{
cout << "a= " << a << " b=" << b << endl;
}
};
const Person operator-(const Person &L, const Person &R)
{
Person tem;
tem.a = L.a-R.a;
tem.b = L.b-R.b;
return tem;
}
int main()
{
Person p1(5,8);
Person p2(9,10);
Person p3 = p1 + p2;
Person p4 = p1 - p2;
p3.show();
p4.show();
return 0;
}