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

  • SEARCH
  • Home
  • 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 8417003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:55:27+00:00 2026-06-10T01:55:27+00:00

Could anybody explain me what is the difference between overload == and < ?

  • 0

Could anybody explain me what is the difference between overload == and <?

For example, if I use a map:

map<Type, int> a();

friend bool operator<(const Type& lhs, const Type& rhs);

friend bool operator==(const Type& lhs, const Type& rhs);

And I implement both operators, when I call:

a.find(value);

The operator function of == is being called? I think not. I debugged and saw that < is called, but why? What should be the behavior of the operator function of <?

I come from Java where the method equals is called and is pretty simple to understand the behavior.

Thanks.

  • 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-10T01:55:29+00:00Added an answer on June 10, 2026 at 1:55 am

    operator== overloads the == operator (and no other); operator<
    overloads the < operator (and no other).

    std::map is defined to use std::less (and only std::less) by
    default, and std::less is defined to use < by default. In general,
    however, I would recommend not overloading operator< unless
    ordered comparison makes sense for your class, in which case, you should
    overload all six comparison operators, in a coherent fashion.
    Otherwise, you can specify a comparison functional type as an additional
    template argument to std::map; the comparison functional object should
    define a strict weak ordering relationship. If the type is designed to
    be used as a key, but the ordering is still purely arbitrary, you might
    specialize std::less.

    As for Java, without operator overloading, it obviously can’t use <;
    by default, SortedMap (the Java equivalent to std::map) requires the
    keys to be Comparable, however, which in turn requires a compare
    function, which returns a value <, == or > 0, depending on whether
    this is <, == or > than other. I’ll admit that I find this a
    little bit more logical, but the difference is very, very small. (The
    rationale behind the C++ decision is that build-in types like int or
    double can be used as keys. In Java, you’ld have to box them.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could anybody explain, why next code isn't compiling? I'm creating a partially-specialized Map and
Can anybody explain the difference in Haskell between the operators ($) and ($!) (dollar
Could anybody explain me what's the difference with setactivewindow with setforegroundwindow (using pinvoke from
Could anybody explain to me the process of uploading to and downloading form and
Could anybody be so kind to give me a simple example of reification in
Could anybody give an example to demonstrate the usage of the Invariant Culture ?
Could anybody brief about user_token functionality in Auth module? What is a use and
Could anybody explain why the static property is null? class Program { static void
Hey, I'm talking about profiles within pom.xml of a project. Could please anybody explain
This code prints out MyUrgentException . Could anybody explain why? class MyException extends Exception{

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.