
On Fri, Jun 17, 2011 at 6:22 PM, Tim Odenthal <Tim.Odenthal@biw.kuleuven.be>wrote:
Hi, all!
I'd like to get a member function of an object to handle signals - is that possible with boost::bind? I tried the following, which doesn't work:
SomeClass{ ... bool done_;
public: void handler_done(int signal){ std::cout << "Recieved signal " << signal <<" ..." <<std::endl; done_ = true; } };
then, in the main: #include <signal.h> #include <boost/bind.hpp> ... SomeClass someClass; signal( SIGINT,boost::bind( &SomeClass::handler_done, &someClass,_1) ); ...
I get the following error (g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3): error: cannot convert ‘boost::_bi::bind_t<void, boost::_mfi::mf1<void, SomeClass, int>, boost::_bi::list2<boost::_bi::**value<SomeClass*>, boost::arg<1> > >’ to ‘void (*)(int)’ for argument ‘2’ to ‘void (* signal(int, void (*)(int)))(int)’
Is this generally impossible, or am I just making some stupid error from not really understanding boost::bind properly?
Thanks in advance!
Tim
That's not going to work, since signal expects a function pointer and not a function object. bind produces function objects. With Kind Regards, Ovanes