
From a quick glance at the ROS API, I don't think there is a way to do it implicitly. I guess its more of a C++ function redefinition functionaility than a ROS functionaility.
You could create a class that inherits from the class outside ROS.
class ClassInsideROS: public ClassOutsideROS {
public:
ClassInsideROS{
// Parent Constructor goes here
}
void new_callback(std_msgs::String::ConstPtr msg) {
std::string msg_string;
// Perform Type Conversion from std_msgs::String::ConstPtr to
old_callback(msg_string)
}
};
void main() {
// Register Callback
ros::NodeHandle n;
ClassInsideROSobj;
ros::Subscriber sub = n.subscribe(topic, 1000, &ClassInsideROS::new_callback, &obj);
}
But if all you need is the member function and no other properties of the class, you could just create a function.
ClassOutsideROS obj_;
void new_callback(std_msgs::String::ConstPtr msg) {
std::string msg_string;
// Perform Type Conversion from std_msgs::String::ConstPtr to
obj_.callback(msg_string)
}
void main() {
// Register Callback
ros::NodeHandle n;
InsideROS obj;
ros::Subscriber sub = n.subscribe(topic, 1000, &ClassOutsideROS::new_callback, &obj);
}
Originally posted by robotchicken with karma: 51 on 2018-04-26
This answer was ACCEPTED on the original site
Post score: 1
Original comments
Comment by vbs on 2018-04-27:
Thank you for your reply. Indeed, that is the same solution I thought of. I was just wondering if really there wasn't any way of doing it implicitly, like using a binding function or something in the subscriber declaration. But I guess that even if there was, it would be less efficient.