I would like to use the same callback for subscriptions to different topics with different types. I have searched on the internet and could not a wokring approach. My idea was to templetize the callback. Something going like this:
template <typename T>
void update_vehicle_callback(const std::shared_ptr<T> msg, const std::string &topic)
This callback would be associated by different subscribers of different topics and different types.
For the sake of clarity let me do an example:
I have topic "cmd_vel" of type Twist and topic "pose" of type PoseStamped. I want to bind to both subscriber the same update_vehicle_callback without defining 2 different callbacks that calls the same method:
void cmd_vel_cb(msg){
update_vehicle_info(msg);
}
void pose_cb(msg){
update_vehicle_info(msg);
}
This is because in reality I have a lot of different topics.
Is there a way to achieve this?