|
Boost Users : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-02-13 18:28:16
Sean Rhea wrote:
> Hello,
>
> Can someone please tell me why this doesn't work?
>
>
> #include <boost/bind.hpp>
> #include <boost/function.hpp>
> #include <boost/shared_ptr.hpp>
>
> using namespace std;
> using namespace boost;
>
> struct MyClass {
> int i;
> void foo(int j){
> printf("%d, %d\n", i, j);
> }
> function<void(int)> bar() {
> return bind<void>(&MyClass::foo, this);
> }
> };
Unlike some other libraries, bind does not automatically append incoming
arguments to the call; if you say bind( f, 5 ), it calls f( 5 ), regardless
of how many input arguments are supplied. If you want the first input
argument to be passed to MyClass::foo, you need to mention it explicitly,
using _1:
bind( &MyClass::foo, this, _1 )
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