版权声明:版权所有 如有侵权 概不追究 https://blog.csdn.net/weixin_40903417/article/details/87980441
#include "stdafx.h"
using namespace std;
class Point
{
public:
Point(double x,double y):_x(x),_y(y)
{
}
~Point()
{
}
Point& operator ++();
Point operator ++(int);
Point& operator --();
Point operator --(int);
friend ostream& operator <<(ostream& out,Point& a);
private:
double _x,_y;
};
Point& Point::operator++()
{
_x++;
_y++;
return *this;
}
Point Point::operator++(int)
{
Point old=*this;
++(*this);
return old;
}
Point& Point:: operator --()
{
_x--;
_y--;
return *this;
}
Point Point::operator --(int)
{
Point old=*this;
--(*this);
return old;
}
ostream& operator<<(ostream& out,Point &a)
{
out<<"("<<a._x<<","<<a._y<<")";
return out;
}
int main()
{
Point a(1,1);
a++;
cout<<a<<endl;
system("Pause");
return 0;
}