Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8711207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:49:02+00:00 2026-06-13T04:49:02+00:00

I understand C++ can’t define operator== automatically for a class, but why can’t it

  • 0

I understand C++ can’t define operator== automatically for a class, but why can’t it use !(a == b) for a != b when operator!= isn’t available but operator== is?

I’m aware of std::rel_ops although I hadn’t heard of it before today.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:49:03+00:00Added an answer on June 13, 2026 at 4:49 am

    Because operator== does not necessarily mean the opposite of operator!=.

    I cannot think of any instance where operator== would not mean !operator!=, but they are separate operators. One of the most liberating and, at times, most frustrating things about C++ is that C++ applies a minimal set of restrictions about how you can write your code. If you have an instance where operator== is not the opposite of operator!=, then you should be able to express that in C++. And, in fact, you can.

    You take the good with the bad in C++. You may consider this to be in the set of “the bad”.

    Bear in mind that in the vast majority of cases, it is trivial to correctly implement operator!= in terms of operator==.

    bool Gizmo::operator!=(const Gizmo& rhs) const
    {
      return !operator==(rhs);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can understand the use for one level of namespaces. But 3 levels of
I understand I can use decorators and filters, but then wouldn't I have to
I can understand the difference between a signed char and an unsigned one. But
So far I can understand HTML.ActionLink and URL.RouteURL but still trying to absorb where
I can understand that WCF is in general better than Remoting, but the two
I understand JSON can be used instead of XMLHttpRequest in Javascript, but can I
I can understand Appdomain concept, but small doubt is One Process -> many application
I understand I can use pointers for functions. Can someone explain why one would
(Someone edit the title if you can understand and define my problem better.) The
I can understand using properties for messages and international settings but I feel there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.