Boost logo

Boost Users :

From: Delfin Rojas (drojas_at_[hidden])
Date: 2008-02-28 13:10:44


> Behalf Of Olaf Peter wrote:
>
> $ LANG=en g++ bind.cpp -o bind && ./bind
> /usr/include/boost/bind.hpp: In member function 'R
> boost::_bi::list2<A1,
> A2>::operator()(boost::_bi::type<R>, F&, A&, long int) [with R = int,
F
> = Foo, A = boost::_bi::list2<const char*&, const int&>, A1 =
> boost::arg<1> (*)(), A2 = boost::arg<2> (*)()]':
> /usr/include/boost/bind/bind_template.hpp:89: instantiated from
> 'typename boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R,
> F,
> L>::operator()(A1&, const A2&) [with A1 = const char*, A2 = int, R =
> int, F = Foo, L = boost::_bi::list2<boost::arg<1> (*)(), boost::arg<2>
> (*)()>]'
> bind.cpp:22: instantiated from here
> /usr/include/boost/bind.hpp:278: error: void value not ignored as it
> ought to be

Foo::operator() is declared void and you are trying to bind it with
bind<int>. If you change it to bind<void> that error will go away, but
you will get another error about not being able to convert int into
int&. I believe this because of the forwarding problem (see the boost
bind documentation under "Limitations"). So, in order to make it work
you need:

struct Bar {

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

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

    Foo& foo;
};

Hope this helps,

-delfin


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