Boost logo

Boost Users :

Subject: [Boost-users] [bind] member function as signal handler
From: Tim Odenthal (Tim.Odenthal_at_[hidden])
Date: 2011-06-17 12:22:07

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:

bool done_;

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!


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at