What is the simplest way to "cast" a member function pointer to a function pointer in C++? -


I want to provide member work for the "comp" parameter of STL algorithm such as low_bound (..., compare) . The comp () function reaches a non-stable member field, so it must be a non-static member itself, but the type of non-static member function pointer is different from a simple function pointer.

What is the best way to deal with this problem?

This is the most common use of std:: Mem_fun and Std :: mem_fun_ref . They are templates that create factators that call the specified member function. TR1 adds a std :: tr1 :: bind which is useful and more versatile (and if you have no TR1 available, depending on it). C ++ 0x will include std :: bind in standard library (virtually unchanged from TR1).


Comments