C++ Comparing Member Function Pointers
c++, pointer-to-member, pointers
Solution
Function pointers are not relationally comparable in C++. Equality comparisons are supported, except for situations when at least one of the pointers actually points to a virtual member function (in which case the result is unspecified).
Of course, you can always introduce an ordering by implementing a comparison predicate and comparing the pointers explicitly (won't look too elegant though, since you can only use equality comparisons). Other possible solutions would cross into the territory of the various implementation-specific "hacks".
Problem
In C++, is it possible to define a sort order for pointers to member functions? It seems that the operator< is undefined. Also, it's illegal to cast to void*. ``` class A { public: void Test1(){} void Test2(){} }; int main() { void (A::* const one)() = &A::Test1; void (A::* const two)() = &A::Test2; bool equal = one == two; //Equality works fine. bool less = one < two; //Less than doesn't. return 0; } ``` Thanks!