Boost logo

Boost :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2001-07-22 20:36:35

On Sunday 22 July 2001 09:05, you wrote:
> Hi,
> i try to compile the 'function'-example from the documentation. I use
> MSVC++ 6.0, SP 5. I have read that there are some glitches with
> MSVC++ and i hope that somebody can help me...
> struct X {
> int foo(int);
> };
> boost::function<int, int> f;
> X x;
> f = std::bind1st(std::mem_fun(&X::foo), &x);
> f(5); // Call
[snip errors]
> Any idea what i can do to run the example, or is there another way of
> assigning a member of X to the 'function'-object? I want to implement
> an event queue where every class can register an event handler. It
> would be cool if those classes just create a 'function'-object, and
> when an event occurs this object is called. From reading the
> documentation that should be possible with 'function' and i really
> would like to use it, it's just that i can't compile...
> Thanks for your help...
> Christoph

First of all, there is no problem with your code. The problem lies with the
C++ library that is shipped with MSVC6 (sp5), because it does not contain the
appropriate versions of the "std::mem_fun" function template. I have three
solutions to your problem, in order of (my own) preference:

1) #include <boost/functional.hpp>, and use boost::mem_fun instead of

2) Use STLport ( instead of MSVC's library. This will
take a bit of work to get it compiled, but the STLport library is _much_
better conforming than the library shipped with MSVC, and you likely won't
run into as many problems with it.

3) Use std::mem_fun1 instead of std::mem_fun. It's non-standard, but it will
work for MSVC (only).


Boost list run by bdawes at, gregod at, cpdaniel at, john at