C++ is operator!= automatically provided when operator== defined
No, operators (apart from assignment) are never automatically generated. It's easy enough to define it in terms of ==
:
bool operator!=(A const & l, A const & r) {return !(l == r);}
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;
before using operator !=
.
What you're after isn't provided by the language for obvious reasons. What you want is provided for by boost::operators
:
class MyClass : boost::operators<MyClass> {
bool operator==(const MyInt& x) const;
}
will get you an operator!=()
based on your operator==()