(一)运算符重载:运算符重载,就是对已有的运算符重新进行定义,赋予其另一种功能,以适应不同的数据类型。

(二)实现类不同对象里中变量的相加

(三)程序

 #include <iostream>
#include <string.h>
#include <unistd.h> using namespace std; class Point {
private:
int x;
int y; public:
Point() {}
Point(int x, int y) : x(x), y(y) {} void printInfo()
{
cout<<"("<<x<<", "<<y<<")"<<endl;
}
friend Point operator+(Point &p1, Point &p2);
}; Point operator+(Point &p1, Point &p2)
{
cout<<"Point operator+(Point &p1, Point &p2)"<<endl;
Point n;
n.x = p1.x+p2.x;
n.y = p1.y+p2.y;
return n;
} int main(int argc, char **argv)
{
Point p1(, );
Point p2(, ); Point sum = p1+p2;
sum.printInfo(); return ;
}

point.cpp

(四)运行结果

最新文章

  1. gradle学习笔记(1)
  2. SSH实战 &#183; SSH项目开发环境搭建
  3. Docker化运维方式讲解
  4. Linux服务器之间的目录共享
  5. Windows Azure Cloud Service (42) 使用Azure In-Role Cache缓存(1)Co-located Role
  6. java中如何实现类似goto的作法
  7. linux命令(11)下查看和添加环境变量
  8. Nodejs文件服务器
  9. Android 调用系统的分享[完美实现同一时候分享图片和文字]
  10. (十二)boost库之多线程高级特性
  11. LeetCode总结 -- 高精度篇
  12. iOS状态变更
  13. HTML学习笔记3:文字和段落
  14. NVIDIA GRID 和 NICE DCV 技术用于实现 Linux 和 Windows&#174; 图形加速虚拟桌面
  15. 设计模式-原型(prototype)
  16. 百道Python入门级练习题(新手友好)第一回合——矩阵乘法
  17. 使用vuex保存singer每个歌星的基本信息
  18. Cannot find entry file index.android.js in any of the roots:[ Android ]
  19. 沉淀再出发:ElasticSearch的中文分词器ik
  20. ISP (互联网服务提供商)

热门文章

  1. Java考题知识点
  2. 【静态延迟加载】self关键字和static关键字的区别
  3. 码云以及Git的使用
  4. 20190804-Python基础 第一章
  5. 怎样理解Cookie
  6. 怎样使用js将文本复制到系统粘贴板中
  7. windows 安装K8s 简易教程
  8. 多线程之thread和runnable
  9. C# 关键字 virtual、override和new的用法
  10. 0基础学习web技术