Boost logo

Boost Users :

Subject: Re: [Boost-users] [bind] member function as signal handler
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2011-06-17 12:56:57


On Fri, Jun 17, 2011 at 6:22 PM, Tim Odenthal
<Tim.Odenthal_at_[hidden]>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



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net