Apologies for the cryptic decryption.
I wish to create a functor of the following type:
const boost::function<bool ()>& functor
Please consider the class:
#include <boost/function.hpp>
class X {
public:
bool foo();
void bar() ;
};
void X::bar() {
const boost::function<bool (X *)>& f = &X::foo;
}
bool X::foo() {
std::cout << __func__ << " " << __LINE__ << " " << std::endl;
return true;
}
I have:
const boost::function<bool (X *)>& f = &X::foo;
Can I have something like
const boost::function<bool ()>& f = &X::foo;
with boost::bind or something else ?
Thanks
A non-static member function must be called with an object. Thus, you must always implicitly pass
this
pointer as its argument.You can accomplish this with
boost::bind
: