博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++Pont类自增运算符重载
阅读量:4315 次
发布时间:2019-06-06

本文共 702 字,大约阅读时间需要 2 分钟。

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

转载于:https://www.cnblogs.com/ganquanfu2008/p/3147081.html

你可能感兴趣的文章
java Graphics2d消除锯齿,使字体平滑显示
查看>>
控件中添加的成员变量value和control的区别
查看>>
Spring Boot Docker 实战
查看>>
Div Vertical Menu ver3
查看>>
Git简明操作
查看>>
InnoDB为什么要使用auto_Increment
查看>>
HDU 1087 Super Jumping! Jumping! Jumping!
查看>>
0007_初始模块和字节码
查看>>
[效率提升]如何管理好你的电脑文件
查看>>
C++实验二
查看>>
零零碎碎的知识
查看>>
文件转码重写到其他文件
查看>>
AC自动机模板
查看>>
python 基本语法
查看>>
git配置
查看>>
【hexo】01安装
查看>>
使用case语句给字体改变颜色
查看>>
JAVA基础-多线程
查看>>
面试题5:字符串替换空格
查看>>
JSP九大内置对象及四个作用域
查看>>