类的operator +操作符满足交换律
来源:互联网 发布:淘宝开店新手入门 编辑:程序博客网 时间:2024/06/03 21:03
例如Spreadsheetcell(单元格)
若operator +作为类的成员函数,因为operator +方法必须Spreadsheetcell对象上调用,对象必须在operator +的左边,
若遇到athirdCell= mycell+4;可以编译,但是athirdCell=4+mycell则通不过编译。
想要解决这个问题,需要通过全局的operator +
const Spreadsheetcell operator +(const Spreadsheetcell &lhs , const Spreadsheetcell& rhs)
{
Spreadsheetcell newCell;
newCell.set(lhs.mValue+rhs.mValue);
return newCell;
}
若operator +访问了Spreadsheetcell Spreadsheetcell operator +需要时Spreadsheetcell 类的友元函数;
class Spreadsheetcell
{
public :
friend const Spreadsheetcell operator +(const Spreadsheetcell &lhs , const Spreadsheetcell& rhs);
}
0 0
- 类的operator +操作符满足交换律
- operator* operator-> 操作符的使用
- boost的operator操作符
- C++操作符operator的另一种用法
- operator= 复制操作符的意外
- operator操作符
- operator 操作符重载
- 操作符(operator)
- VEX Operator(操作符)
- 重载operator操作符
- j2ee Operator 操作符
- C++ 操作符重载 operator = 、operator <
- C++ 操作符重载 operator = 、operator <
- new操作符(new operator) 和 new操作(operator new)的区别
- [C/C++]_[操作符重载operator type()和operator()的区别]
- operator C++ 操作符重载
- 7.3 operator--操作符函数
- operator关键字(重载操作符)
- 年华流淌,红尘若梦
- sqlite3使用简介
- 【整理】Libav、FFmpeg、mplayer、VLC开源项目、FFDshow
- SQL语言细分
- Android 主线程和子线程的关系
- 类的operator +操作符满足交换律
- CoreData 深入理解1
- linux 命令大全
- 软件包 android.annotation 不存在 的解决办法
- linux为什么不怕病毒
- 10款在线网站原型设计工具 总有一款适合你
- Java常用工具类集合
- android百度云推聊(转)
- Windows 7 64位安装cURL