Ask Your Question

Revision history [back]

Just to clarify something, callbacks don't have a return value they are void. You may mean they accept a parameter of type ConstPtr&.

This parameter that is passed to the callback function is a reference to the actual message data stored by ROS message passing system. Creating references to this data is a bad idea since after the callback completes that data will probably stop existing so you'll have invalid pointers, bugs, segfaults and all the things we hate. For this reason your callback function should always make copies of data that you intend to use after the callback has finished.

Your other questions are more general C++ issues, but your question doesn't make any sense without the context of the code it's within. A direct copy, or pointer copy (reference) are always done with an assignment = statement, without an assignment statement we can't answer your question.

I would like to point out that C++ ROS is not a great place to be if you're new to C++. We use some very complex features of the language, I would recommend working through some dedicated C++ tutorials or courses outside of ROS to learn the language itself.