![e3d537ef835d2806371214715e0770f2.png](https://i-blog.csdnimg.cn/blog_migrate/8c2a89582fbd236640e3303e8e7c090c.jpeg)
C.161: Use nonmember functions for symmetric operators
C.161:对称运算使用非成员函数运算符
Reason(原因)
If you use member functions, you need two. Unless you use a nonmember function for (say) ==, a == b and b == a will be subtly different.
如果使用成员函数的话,需要准备两个。除非你使用非成员函数实现==,否则a==b和b==a会有微妙的区别。
Example(示例)
bool operator==(Point a, Point b) { return a.x == b.x && a.y == b.y; }
Enforcement(实施建议)
Flag member operator functions.
提示成员函数操作符。
原文链接:
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c161-use-nonmember-functions-for-symmetric-operators
觉得本文有帮助?请分享给更多人。
更多精彩文章欢迎关注微信公众号【面向对象思考】!
面向对象开发,面向对象思考!