Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The only thing classes add is a scope that can persist variables outside the callback's scope.

In your case, without a class, you could use the global scope.

The only thing classes add (in a case like this, there are obviously other benefits to classes) is a scope that can persist variables outside the callback's scope.

In your case, without a class, you could use the global scope.

The only thing classes add (in a case like this, there are obviously other benefits to classes) is a scope that can persist variables outside the callback's scope.

In your case, without a class, you could use the global scope.


Edit: two alternatives:

  • if using C++11: use a lambda expression and capture chatter_pub, then use that in the lambda body
  • use boost::bind and pass a reference to chatter_pub to the chatter_callback directly