I want to use class member functions as unary functions (for example for <algorithm> calls), I know that that can be done with the <functional> standard library, bind1st(mem_fun1(class::function),this). But when I try to compile this code in MS VC 6:
It gives an error at that last line:Code:#include <algorithm> #include <functional> using namespace std; class foo { public: int f (int x); int g (int x); }; int foo::f(int x) { return x*x; } int foo::g(int x) { return bind1st(mem_fun1(foo::f),this)(x); }The only way to resolve that is to use:error C2784: 'class std::mem_fun1_t<_R,_Ty,_A> __cdecl std::mem_fun1(_R (__thiscall _Ty::*)(_A))' : could not deduce template argument for 'overloaded function type' from 'overloaded function type'However, when I use a global function, like this:Code:int foo::g(int x) { return bind1st(mem_fun1<int,foo,int>(foo::f), this)(x); }It works fine!Code:int global_function(foo* bar, int x) { return bind1st(mem_fun1(foo::f), bar)(x); }
I don't want to make my code look more ugly then it already doesIs this a VC bug? Or is it supposed to do this? Or does anyone know a better way to do this?
(I also tried to write my own mem_fun/bind1st combo class, but that had the same problem)




Is this a VC bug? Or is it supposed to do this? Or does anyone know a better way to do this?
Reply With Quote