Boost logo

Boost Users :

From: Olaf Peter (ope-devel_at_[hidden])
Date: 2008-08-23 06:01:55


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 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