博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
操作符重载调用优先级
阅读量:4630 次
发布时间:2019-06-09

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

先粗略记一下。。。。

对同一个操作符同时实现成员函数重载和友元重载时,优先调用成员重载,当不存在成员重载时调用友元重载

1 #include "stdafx.h" 2  3 class CTest { 4 public: 5     CTest(int nValue) : nValue_(nValue) {} 6  7     friend bool operator ==(const CTest& t1, const CTest& t2) { 8         return t1.nValue_ == t2.nValue_; 9     }10 11     bool operator == (const CTest& t) {12         return nValue_ == t.nValue_;13     }14 15 private:16     int nValue_;17 };18 19 int _tmain(int argc, _TCHAR* argv[])20 {21     CTest t1(1);22     CTest t2(2);23     bool bSame = t1 == t2;24     bSame = t1.operator==(t2);25     bSame = operator == (t1, t2);26     return 0;27 }

 

转载于:https://www.cnblogs.com/mforestlaw/p/4891018.html

你可能感兴趣的文章
bootstrap 冻结表格,冻结表头
查看>>
Python之路-python(Queue队列、进程、Gevent协程、Select\Poll\Epoll异步IO与事件驱动)
查看>>
Centos修改系统语言
查看>>
仿人智能控制器的参数简化(已发表于《计算机测量与控制》2013年第4期)
查看>>
Flink学习笔记:Operators之CoGroup及Join操作
查看>>
TSP问题——动态规划
查看>>
kmp练习
查看>>
python xml模块学习
查看>>
[WCF] - Odata Service 访问失败,查看具体错误信息的方法
查看>>
【2019/4/30】周进度报告
查看>>
.net程序员面试题
查看>>
团队分数分配方法——BY 李栋
查看>>
docker获取镜像很慢解决办法
查看>>
学习-现代交换原理与通信技术
查看>>
【编程题目】左旋转字符串 ☆
查看>>
SQL Server 2008 R2如何开启数据库的远程连接
查看>>
笔记一:python安装和执行
查看>>
关于字符串的分割问题
查看>>
Tornado 类与类组合降低耦合
查看>>
2009 Competition Highlights by ICPC Live
查看>>