Boost logo

Boost Users :

Subject: Re: [Boost-users] Using boost.signals with boost.bind
From: Jeff Gray (jeffg_at_[hidden])
Date: 2008-10-13 20:09:04


Sergey Kishchenko wrote:
> I have one problem with boost.bind and boost.signals I can't understand.

I have used bind with signals in a simpler way than you have in this
example. It works well for me. I don't know if you are doing it in a
more complex way for a reason, but hopefully my simple version will be
some help.

class MyClass
{
public:
  MyClass(void)
  { // define the connection using bind
    mySignal.connect(
      boost::bind(&MyClass::MySlot,this,_1));
  }
  boost::signal<void (bool)> mySignal;
private:
  void MySlot(bool state)
  { // do something here to process the signal data when this is called
  }
};

// later on, to call that signal
inst = MyClass();
inst.mySignal(1);

This is all pretty straightforward. This only unusual thing (for me) is
the use of _1 as a marker for the first parameter. If you have a
function with more parameters, then the next parameter would be _2 and
so on.


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