首页 > 其他 > 详细

操作符重载调用优先级

时间:2015-10-19 10:38:38      阅读:216      评论:0      收藏:0      [点我收藏+]

先粗略记一下。。。。

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

 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 }

 

操作符重载调用优先级

原文:http://www.cnblogs.com/mforestlaw/p/4891018.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!