Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 08-02-2010
Member
 
Join Date: Jan 2010
Posts: 57
No match for operator<

I'm using a map and, at the time of compilation, I get this error:
Quote:
no match for ?operator<? in ?__x < __y?
line 230, external location: /usr/include/c++/4.4/bits/stl_function.h
I am using g++ under Linux. My map is declared as follows:
Code:
map<MyEvent, void(*)()> nameMap;
I need to combine a function (returning void) to a certain event. When this event is raised, the associated function is called.

Can someone help me why and what is the error message refers to?
Reply With Quote
  #2  
Old 08-02-2010
Member
 
Join Date: Nov 2008
Posts: 1,192
Re: No match for operator<

Did you tried entering this in the code?

Code:
#include <map>
using namespace std;
And is MyEvent is defined somewhere? Maybe it's better if it carries a few lines of code in more

I thus established:

Code:
#include <iostream>
#include <map>
using namespace std;

int main ()
{

map<int, void(*)()> nameMap;

return 0;
}
So surely the problem is the definition of MyEvent
Reply With Quote
  #3  
Old 08-02-2010
Member
 
Join Date: Jan 2010
Posts: 57
Re: No match for operator<

Quote:
Originally Posted by void View Post
Did you tried entering this in the code?

Code:
#include <map>
using namespace std;
And is MyEvent is defined somewhere? Maybe it's better if it carries a few lines of code in more
MyEvent is taken from an external library. And, of course, I imported the header <map> and the declaration use std::map<...>.

Is there anyone else with an idea?
Reply With Quote
  #4  
Old 08-02-2010
Member
 
Join Date: May 2008
Posts: 2,293
Re: No match for operator<

The reason for not working and 'written in the error message: no operator <for the type key (ie MyEvent), which serves to map to distinguish different elements (or rather sort tree).

Once deployed, the operator error should disappear. Alternatively you can use a different name, and pass it as the third argument of the template of map <>
Reply With Quote
  #5  
Old 08-02-2010
Member
 
Join Date: Jan 2010
Posts: 57
Re: No match for operator<

Quote:
Originally Posted by Zecho View Post
The reason for not working and 'written in the error message: no operator <for the type key (ie MyEvent), which serves to map to distinguish different elements (or rather sort tree).
Unfortunately I can not change MyEvent, as it is part of a library of third parties.

Quote:
Originally Posted by Zecho View Post
Once deployed, the operator error should disappear. Alternatively you can use a different name, and pass it as the third argument of the template of map <>
What do you mean by a "different name"?
Reply With Quote
  #6  
Old 08-02-2010
Member
 
Join Date: May 2008
Posts: 2,293
Re: No match for operator<

You can implement it without touching the class as a function
Code:
bool operator < ( const MyEvent& x, const MyEvent& y );
Quote:
What do you mean by a "different name"?
By that I mean you must use a function object:
Code:
struct compare
{
    bool operator ()( const MyEvent& x, const MyEvent& y )
    {
        return ???;
    }
};


int main()
{
    map<MyEvent,bool,compare> myMap;

    ...
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "No match for operator<"
Thread Thread Starter Forum Replies Last Post
L4D - Server Operator boos Video Games 1 06-10-2009 02:52 PM
Error in Operator Overloading DutchDude Software Development 2 13-05-2009 11:54 PM
Choose your ISD/STD operator Rahul45 India BroadBand 1 05-02-2009 02:21 PM
Which is best CDMA Operator in INDIA ? Makrand India BroadBand 1 15-12-2008 02:35 PM


All times are GMT +5.5. The time now is 01:58 AM.