Boost logo

Boost Users :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2003-11-22 12:53:32


On Friday 21 November 2003 05:33 pm, Kim wrote:
> Can't get an example similar to the one found in the tutorial to work.
>
> // *************************************
> #include <boost/function.hpp>
> #include <functional>
>
> struct X
> {
> int foo(int v) { return v;}
> };
>
> int main(int argc, char* argv[])
> {
> boost::function1<int, int> f;
> X x;
> f = std::bind1st
> (
> std::mem_fun(&X::foo),
> &x
> );
> f(5); // Call x.foo(5)
> return 0;
> }
>
> //***************************************
>
> I get this error message:
> : error C2784: 'class std::mem_fun_t<_R,_Ty> __cdecl std::mem_fun(_R
>
> (__thiscall _Ty::*)(void))' : could not deduce template argument for
> '<Unknown>' from 'int (__thiscall X::*)(int)'

I believe this is actually a bug in the standard library that ships with MSVC
6.0. I suggest you use Boost.Bind instead:
  f = boost::bind(&X::foo, &x, _1);

        Doug


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net