Problem Using Class function as callback
I'm trying to encapsulate nodes to support dynamic node creation. When I try to register a callback from inside a class using one of that classes functions I get a compile error. The following code works correctly if I do static callback()
.
class node {
private:
ros::NodeHandle *n;
public:
node(int argc, char **argv, std::string s) {
n = NULL;
ros::init(argc, argv, s);
}
bool node::create() {
if (n == NULL) {
n = new ros::NodeHandle();
return true;
}
return false;
}
ros::NodeHandle getHandle() {return *n;}
};
class coordinator
{
private:
node myNode;
ros::Subscriber sub;
public:
void setup() {
//assume myNode() has been called correctly
myNode.create();
//this does not compile
sub = myNode.getHandle().subscribe("telemetry", 1000, &coordinator::callback);
}
void callback(const TelemetryUpdate::ConstPtr& msg) {;/** stuff */}
};