I'm trying to shoehorn in some boost::bind to substitute member functions for straight up C function pointer style callbacks, but I'm running into problems doing the obvious thing. Can someone tell me why the following code snippet can't seem to match up the types in the function call?
#include <iostream>
#include <boost/bind.hpp>
using namespace std;
class Foo {
public:
Foo(const string &prefix) : prefix_(prefix) {}
void bar(const string &message)
{
cout << prefix_ << message << endl;
}
private:
const string &prefix_;
};
static void
runit(void (*torun)(const string &message), const string &message)
{
torun(message);
}
int
main(int argc, const char *argv[])
{
Foo foo("Hello ");
runit(boost::bind<void>(&Foo::bar, boost::ref(foo), _1), "World!");
}
boost::functionand a function that takes aconst&to the typedef in a namespace ought to work if you must. Then you can useboost::bindwhen calling the namespace function with whatever you want.