in Education by
I would like to know if I can compare 2 member functions with the "<" operator. I can do "==" but I can't use it in the case below. I tried casting them to void* but that won't work either. template <class Receiver, class Sender> class CallBack2 : public ICallBack2 { protected: Receiver* receiver; void(Receiver::*function)(Sender*); Sender* sender; public: CallBack2(Receiver* _receiver, void(Receiver::*_function)(Sender*), Sender* _sender) : receiver(_receiver), function(_function), sender(_sender) {}; virtual ~CallBack2() {}; virtual void callBack() { (receiver->*function)(sender); } virtual bool operator<(const ICallBack2* _other) const { CallBack2<Receiver, Sender>* other = (CallBack2*)_other; if (receiver < other->receiver) { return true; } else if (receiver == other->receiver && function < other->function) { return true; // this line gives the error } return false; } }; Any ideas please? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
C++03 § 5.9, which covers the semantics of the built-in <, >, <= and >=, doesn't mention pointers to members and states: Other pointer comparisons are unspecified. According to § 8.3.3, 3 The type "pointer to member" is distinct from the type "pointer", As a result, we can conclude the result of relational operators applied to pointers to members (whether functions or fields) is unspecified. Note that "unspecified behavior" is different from "undefined behavior", but still means you can't usefully apply the operators as different implementations may have different results. "Unspecified" basically means the implementation gets to define the behavior.

Related questions

0 votes
    I would like to know if I can compare 2 member functions with the "...
asked Feb 27, 2022 in Education by JackTerrance
0 votes
    I would like to know if I can compare 2 member functions with the "...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    I would like to know if I can compare 2 member functions with the "...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    Which function in R language is used to find out whether the means of 2 groups are equal to each other ... Debugging of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    I am following simple examples to build up my understanding on private static members. However, I am getting ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    Which of the following may be used for linear regression? (a) X %*% Y (b) solve(A) (c) solve(A ... Linear Regression of R Programming Select the correct answer from above options...
asked Feb 11, 2022 in Education by JackTerrance
0 votes
    ________ functions can be built which contain all of the necessary data for evaluating the function. (a) ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    I am coding a Gameboy Emulator, and for the CPU's instructions I use this struct here (in cpp.hpp ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    I have defined an interface in C++, i.e. a class containing only pure virtual functions. I want ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 13, 2022 in Education by JackTerrance
0 votes
    I have defined an interface in C++, i.e. a class containing only pure virtual functions. I want ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 13, 2022 in Education by JackTerrance
0 votes
    I have defined an interface in C++, i.e. a class containing only pure virtual functions. I want ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 13, 2022 in Education by JackTerrance
0 votes
    Which of the following package contains functions for reading and displaying satellite data for oceanographic ... Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Which of the following contains functions for processing uniaxial minute-to-minute accelerometer data? (a) ... R Programming Select the correct answer from above options...
asked Feb 10, 2022 in Education by JackTerrance
0 votes
    #include struct A { bool f( int a ) { std::cout...
asked Feb 21, 2022 in Education by JackTerrance
...