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 8901055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:15:16+00:00 2026-06-15T01:15:16+00:00

class A { private: int a; public: A( int set ) { a =

  • 0
class A
{
private:
    int a;
public:
    A( int set )
    {
        a = set;
    };
    ~A();
    bool operator <(const A& ref )
    {
        return this->a < ref.a;
    };
    bool operator ==(const A& ref )
    {
        return this->a == ref.a;
    };
};

int _tmain(int argc, _TCHAR* argv[])
{

    map<A,int>m;
    A a( 1 );
    m.insert( make_pair( a, 2 ) );
    for( map<A,int>::iterator it = m.begin(); it != m.end(); ++it )
    {

    }
    return 0;
}

Generates C2678: http://msdn.microsoft.com/en-us/library/ys0bw32s(v=vs.80).aspx

for the operator <

and if I use m.find will also generate for the operator ==
How to get around with this?

To be more specific the error leads to:

template<class _Ty>
    struct less
        : public binary_function<_Ty, _Ty, bool>
    {   // functor for operator<
    bool operator()(const _Ty& _Left, const _Ty& _Right) const
        {   // apply operator< to operands
        return (_Left < _Right);
        }
    };

on functional

Final case:

struct MASTERPLAYER
{
    int a;
    bool operator==( const MASTERPLAYER& ref ) const 
    {
        return a == ref.a;
    }
};

int _tmain(int argc, _TCHAR* argv[])
{

    MASTERPLAYER m;
    vector<MASTERPLAYER>v;
    v.push_back( m );
    std::find( v.begin(), v.end(), 2 );

}

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

    You want to mark the functions as const, to signify that they don’t modify the object on which they’re invoked:

    bool operator <(const A& ref ) const
    {
        return a < ref.a;
    };
    bool operator ==(const A& ref ) const
    {
        return a == ref.a;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Tango with D1: class C { private int j; public int opBinary(char[] op:
I have a C++ program: class X { private: int a; public: int func(char
class Celda { private: int* bloques_; public: Celda(int size); ~Celda(){ delete [] bloques_; };
public class Arrys { private int[] nums; //Step 3 public Arrys (int arrySize) {
public class Ex7 { private int fld; private void meth(int val) { fld =
Superclass source code public class Date { private int month; private int day; private
I have following class public class ButtonChange { private int _buttonState; public void SetButtonState(int
@Entity @Table(name=Product_info) public class Product { private int ProductIndex; private int priority; private Date
[AttributeUsage(AttributeTargets.Method,AllowMultiple=true)] public class MethodId : Attribute { private int mId; public MethodId(int mId) {
these are my entities (simplified): public class IdentificationRequest { private int id; private ICollection<IdentificationRequestStateHistoryItem>

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.