Results 1 to 6 of 6

Thread: No match for operator<

  1. #1
    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:
    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?

  2. #2
    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

  3. #3
    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?

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    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 <>

  5. #5
    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"?

  6. #6
    Join Date
    May 2008
    Posts
    2,297

    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 );
    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;
    
        ...
    }

Similar Threads

  1. L4D - Server Operator
    By boos in forum Video Games
    Replies: 1
    Last Post: 06-10-2009, 02:52 PM
  2. Error in Operator Overloading
    By DutchDude in forum Software Development
    Replies: 2
    Last Post: 13-05-2009, 11:54 PM
  3. Choose your ISD/STD operator
    By Rahul45 in forum India BroadBand
    Replies: 1
    Last Post: 05-02-2009, 02:21 PM
  4. Which is best CDMA Operator in INDIA ?
    By Makrand in forum India BroadBand
    Replies: 1
    Last Post: 15-12-2008, 02:35 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,872,497.86226 seconds with 16 queries