ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I assume this is e. g. of type MyDerivedClass* where MyDerivedClass inherits from MyClass and the method StageOdom_callback of class MyClass is protected or public (not private!).

If so have you tried:

ros::Subscriber StageOdo_sub = n.subscribe<nav_msgs::Odometry>("robot_0/odom",1000, &MyClass::StageOdom_callback, dynamic_cast<MyClass*>( this ) );

If your compiler does not provide dynamic_cast you could also use reinterpret_cast<MyClass*>. However, dynamic_cast is safer as it checks at runtime that the class of the object pointed to by this really inherits from MyClass...

I assume this is e. g. of type MyDerivedClass* where MyDerivedClass inherits from MyClass and the method StageOdom_callback of class MyClass is protected or public (not private!).

If so have you tried:

ros::Subscriber StageOdo_sub = n.subscribe<nav_msgs::Odometry>("robot_0/odom",1000, n.subscribe("robot_0/odom",1000, &MyClass::StageOdom_callback, dynamic_cast<MyClass*>( this ) );

If your compiler does not provide dynamic_cast you could also use reinterpret_cast<MyClass*>. However, dynamic_cast is safer as it checks at runtime that the class of the object pointed to by this really inherits from MyClass...

Edit: you do not need to explizitly select the template type (<nav_msgs::Odometry>) like you do with advertise. The Template type is implizitly selected from the callback argument type...

I assume this is e. g. of type MyDerivedClass* where MyDerivedClass inherits from MyClass and the method StageOdom_callback of class MyClass is protected or public (not private!).

If so have you tried:

ros::Subscriber StageOdo_sub = n.subscribe("robot_0/odom",1000, &MyClass::StageOdom_callback, dynamic_cast<MyClass*>( this ) );

If your compiler does not provide dynamic_cast you could also use reinterpret_cast<MyClass*>. However, dynamic_cast is safer as it checks at runtime that the class of the object pointed to by this really inherits from MyClass...

Edit:

I just noticed: you do not need to explizitly select the template type (<nav_msgs::Odometry>) like you do with advertise. The Template type is implizitly selected from the callback argument type...