Register protected callback in base class
Hi! The compiler complains about me trying to subscribe to messages and register a parent's class protected callback method. Here is the (simplified) code:
class Base{
public:
Base () {}
protected:
void callback(const CameraInfoConstPtr & msg) { ... }
ros::Subscriber sub;
}
class Derived : public Base{
public:
Derived() {
NodeHandle nh;
sub = nh.subscribe("topic", 1,
&Base::callback,
dynamic_cast<Base*>(this));
}
}
And this is the compiler (g++) error:
error: 'void Base::callback(const CameraInfoConstPtr&)' is protected
The problem dissolves if I make the callback public, but I do not want to do that. Can somebody explain why it does not work and show a workaround? Thank you!
I believe this is more of a C++ problem and less of a ROS problem. It seems to me that changing
&Base::callback
to&Derived::callback
should fix the issue: http://stackoverflow.com/questions/14...This may not be exactly what you want... I'm not sure what you are trying to accomplish, but I do believe the error is related to the context inside of
Derived