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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:23:58+00:00 2026-05-29T16:23:58+00:00

As described in another message of mine , it is not possible to compare

  • 0

As described in another message of mine, it is not possible to compare 2 pointers to member functions with “<” (less than). Or at least, this causes undefined behavior.

I have just managed to compile this code both with Visual C++ as well as GCC:

template <class Receiver, class Param = void*, class Return = void>
class EventReceiver : public IFunction<> {

protected:

    std::set< Return(Receiver::*)(Param) > test;
    std::set< Return(*)(Param) > test2;
...

AFAIK, to make a std::map or std::set of anything, it must be possible to compare the set’s values with “<“. Does this mean that the above containers or the actual compilers have a working implementation of comparing pointers-to-methods in such a way?

  • 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-05-29T16:24:00+00:00Added an answer on May 29, 2026 at 4:24 pm

    Well, it was in reality misleading that the example code compiled. The truth is that the sets are unusable. Every attempt to insert data into them produces the expected error.

    That’s the “dark side” of C++ template functions. They don’t exist till you use them (and thus won’t produce compiler errors till you do).

    Check this out :

    #include <set>
    
    class X {};
    
    int main() {
    
        typedef void(X::*FuncPtr)();
        std::set< FuncPtr > set;
        std::less< FuncPtr > less;
        FuncPtr f1;
        FuncPtr f2;
        //set.insert(f1);   // both of these lines
        //less(f1,f2);      // produce an error
    };
    

    Removing the comments in any of the last 2 lines produces the error :

    invalid operands of types ‘void (X::* const)()’ and ‘void (X::*
    const)()’ to binary ‘operator<’

    Compile it online yourself here.

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

Sidebar

Related Questions

This is the problem described in Programming pearls . I can not understand binary
This is just another working in dev server, why not working in IIS type
This question is another problem im having with my application which is described here
I have instructions on creating a checksum of a message described like this: The
The algorithm is described in this paper: Thread Scheduling for Multiprogrammed Multiprocessors . Briefly,
Here is well described how to call member function by pointer: http://www.newty.de/fpt/functor.html But the
I run into the same issue described there: Another StackOverflow Question I need to
I used the trick described in this question to display a FireMonkey form on
As described in this question , I'm working on a method that returns the
I have a very similar problem to the one described in this question .

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.