题目
定义Point类,有坐标_x,_y两个成员变量;对Point类重载“++”(自增)、“–”(自减)运算符,实现对坐标值的改变。
C++代码如下:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859#include
using namespace std;
class Point
{
private:
int x,y;
public:
Point(int a,int b){x=a,y=b;}
Point& operator++();
Point operator++(int);
Point& operator--();
Point operator--(int);
void showPoint();
};
Point & Point::operator++()//前置++
{
++x,++y;
return *this;
}
Point Point::operator++(int)//后置++
{
x++,y++;
return *this;
}
Point & Point::operator--()//前置--
{
--x,--y;
return *this;
}
Point Point::operator--(int)//后置--
{
x--,y--;
return *this;
}
void Point::showPoint()
{
cout |