#include <iostream>
using namespace std; class CVector
{
public:
int x, y;
CVector()
: x(), y()
{
}
CVector(int a, int b)
: x(a), y(b)
{
}
;
CVector operator +(const CVector&);
}; //+号是双目运算,这个成员函数的形式
CVector CVector::operator +(const CVector& param)
{
CVector temp;
temp.x = x + param.x;
temp.y = y + param.y;
return temp;
} //+号的非成员函数形式
CVector operator+(const CVector& lhs, const CVector& rhs)
{
cout<<"no member function"<<endl;
CVector temp;
temp.x = lhs.x + rhs.x;
temp.y = lhs.y + rhs.y;
return temp;
}
/**
*运算符重载表,注意成员函数和非成员函数的区别
* Expression Operator Member function Non-member function
* @a + - * & ! ~ ++ -- A::operator@() operator@(A)
* a@ ++ -- A::operator@(int) operator@(A,int)
* a@b + - * / % ^ & | < > == != <= >= << >> && || , A::operator@(B) operator@(A,B)
* a@b = += -= *= /= %= ^= &= |= <<= >>= [] A::operator@(B) -
* a(b,c...) () A::operator()(B,C...) -
* a->b -> A::operator->() -
* (TYPE) a TYPE A::operator TYPE() -
*/ int main()
{
CVector foo(, );
CVector bar(, );
CVector result;
CVector result2 = foo.operator +(bar);
result = foo + bar;
CVector result3 = foo+bar;
cout << result.x << ',' << result.y << endl;
cout << result2.x << ',' << result2.y << endl;
cout << result3.x << ',' << result3.y << endl;
return ;
}

最新文章

  1. 从零开始编写自己的C#框架——框架学习补充说明
  2. c 算牌器代码
  3. 如何牢记C/C++中const的用法?
  4. shell 显示字体颜色
  5. linux笔记:shell基础-概述和脚本执行方式
  6. malloc函数详解
  7. SAP和Java系统的Webservice实例
  8. javascript单元测试工具
  9. Shell学习笔记 - Shell变量
  10. 在Xcode6中找回失去的模板
  11. Android开发UI之动画侦听
  12. 玩转Android之数据库框架greenDAO3.0使用指南
  13. HDU 4276 The Ghost Blows Light(树形)
  14. 使用Pycharm 安装三方库
  15. flash Ane
  16. delegate vs event
  17. PyCOn2013大会笔记
  18. Python实现身份证号码有效性验证
  19. 4337: BJOI2015 树的同构
  20. python 彩色日志配置

热门文章

  1. hdu 1203 dp(关于概率的```背包?)
  2. java二叉树排序实现
  3. 【BZOJ3110】【Zjoi2013】K大数查询 - 2
  4. cuda+ffmpeg+opengl解码rtsp h264码流多路
  5. 在Docker中运行crontab
  6. GStreamer插件分类
  7. ubuntu 14.04安装OVS虚拟OpenFlow交换机配置总结
  8. tomcat源码阅读之Catalina和Bootstrap解析
  9. http常用状态码说明
  10. JZ2440 裸机驱动 第13章 LCD控制器(1)