#include <iostream>
using namespace std;
/**
* 定义Coordinate类
* 数据成员:m_iX,m_iY
* 成员函数:构造函数
* 重载--运算符,重载+运算符
*/
class Coordinate
{
public:
Coordinate(int x, int y)
{
m_iX = x;
m_iY = y;
}
// 前置--运算符重载
Coordinate& operator--()
{
m_iX=m_iX--;
m_iY=m_iY--;
return *this;
}
// 后置--运算符重载
Coordinate operator--(int)
{
Coordinate old(*this);
m_iX= m_iX--;
m_iY= m_iY--;
return old;
}
// +号运算符重载
Coordinate operator+(const Coordinate &coor)
{
Coordinate add(0,0);
add.m_iX=m_iX+coor.m_iX;
add.m_iY=m_iY+coor.m_iY;
return add;
}
void show()
{
cout << m_iX << m_iY << endl;
}
public:
int m_iX;
int m_iY;
};
int main(void)
{
Coordinate coor1(1, 3);
Coordinate coor2(2, 4);
Coordinate coor3(0, 0);
coor1--;
coor1.show();
--coor2;
coor2.show();
coor3 = coor1 + coor2;
cout << coor3.m_iX << endl;
cout << coor3.m_iY << endl;
return 0;
}