Calling ros::NodeHandle::subscribe with a topicname constructed by sprintf
My Topic names are supposed to change, when I use different sensors. Therefor I want my node to subscribe to different topics depending on parameters on the parameter server. I tried to use this in my CPP node:
char left_camera_topic[50]
std::string camera_type;
n.getParam("/neuromorphic_stereo/config/camera_type", camera_type);
sprintf(left_camera_topic,"/%s_left/events",camera_type);
ros::Subscriber leftCam = n.subscribe(left_camera_topic_string, subscriberCallback);
with
void subscriberCallback(const dvs_msgs::EventArray& msg);
But building this gets me the error
error: no matching function for call to 'ros::NodeHandle::subscribe(const char [50], void (&)(const EventArray&))' ros::Subscriber leftCam = n.subscribe(left_camera_topic_string, subscriberCallback);
Is it not possible to construct the topicnames like this, or am I doing something wrong?
Why did you delete your question?
@gvdhoorn I'm sorry I deleted the question before you posted your answer because I just did a stupid mistake: I forgot the buffer-size argument of the subscribe function. adding that argument makes the code work and your answer therefor doesn't solve the problem.
@gvdhoorn I could, of course, reopen the question and you adjust your answer to fit the solution. And thanks for the remapping suggestion, I'll have a look at that.
I would suggest to re-open the question, and answer your own question. Then accept that answer.