Reply to comment

boost signals

I'm sure you know them already, but your example would be even cleaner and easier with boost signals. The entire CallbackHandler would be unnessesary:

class ClassWithCallbacks
{
public:
	void registerSelf(boost::signal<void ()> & callbackHandler)
	{
		callbackHandler.connect(boost::bind(&ClassWithCallbacks::callback1, this));
		callbackHandler.connect(boost::bind(&ClassWithCallbacks::callback2, this));
	}
private:
	void callback1() { /* bla */ }
	void callback2() { /* more bla */ }
};

usage:

boost::signal<void ()> sig;
ClassWithCallbacks justAClass;
justAClass.registerSelf(sig);
 
//do Callbacks:
sig();

BTW, I think there's a typo in your Listing's: Shouldn't it be

private:
  void callback1() { /* dosomething */ }
  void callback2() { /* dosomething */ }

instead of
private:
  void callback1Impl() { /* dosomething */ }
  void callback2Impl() { /* dosomething */ }

greetings, iliis

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.
  • You may post PHP code. You should include <?php ?> tags.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <cpp>. The supported tag styles are: <foo>, [foo]. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.
  • Images can be added to this post.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
2 + 5 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.