首页 > 编程知识 正文

重载自增运算符,自增自减运算符详解

时间:2023-05-04 23:08:32 阅读:235936 作者:246

#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;
}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。