Hi,
the following code doesn't compile:
---8<---
#include <iostream>
#include
#include
using namespace std;
using namespace boost;
struct foo {
function 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::bind(F, A1) [with F = void
(bar::*)(const std::string&), A1 = bar*]
/usr/include/boost/bind.hpp:1628: note:
boost::_bi::bind_t::type,
boost::_mfi::dm, 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