Jump to content
  • Advertisement
Sign in to follow this  
Pooya65

boost.signal and class

This topic is 3172 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi how can i connect a member of class to the boost.signal?? for example, i want to connect func1 of the flowing class to the signal:
;
class test
{
public:
  void func1(){cout << "hello world" << endl;};
};

;

Share this post


Link to post
Share on other sites
Advertisement
you have to bind 'this' pointer with member function first:

someSignal.connect(boost::mem_fn(&test::func1));

of

someSignal.connect(boost::bind(&test::func1, _1));

use second when there is more parameters to pass to a method call, and check out boost::bind documentation

Share this post


Link to post
Share on other sites
hi

i try it. but this isnt work:


class test
{
public:
void func()
{
cout << "hello class" << endl;
}
};

void main(void)
{
test a;
boost::signal<void ()> sig;

sig.connect(boost::mem_fn(&test::func));

sig();
}

Share this post


Link to post
Share on other sites
The example posted by noe isn't actually correct, it should be:
sig.connect(boost::bind(&test::func, &a));
That is, you have to actually pass an instance for "this" as the second parameter.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!