C++Pont类自增运算符重载

#include <string>
#include <cmath>

#include <iostream>
using namespace std;

#include <asio.hpp>

class Point
{
private:
 int m_nX;
 int m_nY;

public:
 Point()
 {
  this->m_nX = 0;
  this->m_nY = 0;
 }
 Point(int x, int y)
 {

  this->m_nX = x;
  this->m_nY = y;

 }

 void ShowPoint()
 {
  cout << "坐标:" << "(" << this->m_nX << "," << this->m_nY << ")" << endl;
 }

 friend void operator ++(Point &point);
 ~Point()
 {


 }
};

 

void operator ++(Point &point)
{
 ++point.m_nX;
 ++point.m_nY;
}


int main()
{

 

 Point pont(100, 100);
 pont.ShowPoint();//输出坐标:(100,100)

 ++pont;
 pont.ShowPoint();//输出坐标:(101,101)

 pont++;
 pont.ShowPoint();//输出坐标:(102,102)
 
 int wait;
 cin >> wait;
 return 0;
}

posted @ 2013-06-20 20:46  Predator  阅读(254)  评论(0编辑  收藏  举报