C ++是operator!=定义了operator ==时自动提供 [英] C++ is operator!= automatically provided when operator== defined
本文介绍了C ++是operator!=定义了operator ==时自动提供的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否在我的班级中定义了operator ==时自动提供了operator!=?当我在A类中定义了operator ==时,显然A a,A b,a == b有效,但是!= b则无效.但是我不确定是否总是这样.有什么例外吗?
I wonder if operator!= is automatically provided when operator== is defined within my class? When I have operator== defined in class A, obviously A a, A b, a == b works, but a != b doesn't. However I am not sure if it always happens. Are there any exceptions from this?
推荐答案
为您自动提供的 not 操作符!=
.如果您想要这样的自动化,则可能需要阅读 rel_ops 命名空间.基本上你可以说
The operator !=
is not automatically provided for you. You may want to read about rel_ops namespace if you want such automation. Essentially you can say
using namespace std::rel_ops;
在使用 operator!=
之前.
这篇关于C ++是operator!=定义了operator ==时自动提供的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文