Boost logo

Boost Users :

From: Stefan Demharter (sdemharter_at_[hidden])
Date: 2008-02-29 05:21:33


Hi,

bind makes copies of the given parameters and operates on them. If you
want bind to operate on a reference of the given object, you should use
boost::ref.

struct Bar {

    Bar( Foo& foo_ ) : foo( foo_ ) { }

    void operator()( const char* s_ ) {
        bind<void>(boost::ref(foo), _1, 42)(s_);
    }

    Foo& foo;
};

This results in:
$ ./a.out
Hallo, 42

Greetings, Stefan

On Do, 2008-02-28 at 21:04 +0100, Olaf Peter wrote:
> Thanks a lot, the wrong return type was stupid ...
>
> > struct Bar {
> >
> > Bar( Foo& foo_ ) : foo( foo_ ) { }
> >
> > void operator()( const char* s_ ) {
> > bind<void>(foo, _1, 42)(s_);
> > }
> >
> > Foo& foo;
> > };
> >
> > That compiles for me in VC++ 8
>
> yes, but I do not get the expected output, I was not carefully enough?
>
> $ ./bind
> X, 11


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