Boost logo

Boost Users :

From: Peter Barker (newbarker_at_[hidden])
Date: 2008-08-23 09:03:02


--- On Sat, 23/8/08, Olaf Peter <ope-devel_at_[hidden]> wrote:

> From: Olaf Peter <ope-devel_at_[hidden]>
> Subject: [Boost-users] [function] creating function object for member function call delegation
> To: "Boost.Org Users" <boost-users_at_[hidden]>
> Date: Saturday, 23 August, 2008, 11:01 AM
> Hi,
>
> the following code doesn't compile:
>
> ---8<---
> #include <iostream>
> #include <boost/function.hpp>
> #include <boost/bind.hpp>
>
> using namespace std;
> using namespace boost;
>
>
> struct foo {
>
> function<void ( const string& )> fn;
> };
>
> struct bar {
>
> foo& m_f;
>
> bar(foo& f) : m_f( f )
> {
> m_f.fn = bind( bar::write, this); // L20
> }
>
> void write( const string& s ) {
> cout << s;
> }
> };
>
>
> int main()
> {
> foo f;
> bar b( f );
> f.fn( "Hello\n" );
>
> }
> --->8---
>
> class foo (object f) gets called with the string argument
> and shall
> delegate the call to the write function of bar. Writing
> bind(
> bar::write, this, _1) doesn't make things better.
>
> Here the error message:
>
> $ LANG=en g++ callback.cpp -o callback
> callback.cpp: In constructor 'bar::bar(foo&)':
> callback.cpp:20: error: no matching function for call to
> 'bind(<unresolved overloaded function type>, bar*
> const)'
> /usr/include/boost/bind.hpp:1383: note: candidates are:
> boost::_bi::bind_t<boost::_bi::unspecified, F, typename
> boost::_bi::list_av_1<A1>::type> boost::bind(F,
> A1) [with F = void
> (bar::*)(const std::string&), A1 = bar*]
> /usr/include/boost/bind.hpp:1628: note:
> boost::_bi::bind_t<typename boost::_bi::dm_result<M
> T::*, A1>::type,
> boost::_mfi::dm<M, T>, typename
> boost::_bi::list_av_1<A1>::type>
> boost::bind(M T::*, A1) [with A1 = bar*, M = void ()(const
> std::string&), T = bar]
>
> Thanks for help,
> Olaf
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users

Try adding the _1 placeholder:

m_f.fn = bind( bar::write, this, _1); // L20


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