I am quite new to C++. I know that callbacks with return type of ConstPtr& are of boost::shared_ptr<const MsgType> type.

Now, when dealing with callbacks, does one copy or initialize objects by reference? For example, I have a ROS msg with fields int x and int y[]. Within the callback, would I copy x and y or initialize references for both of them?

Another thing, how can I know which objects are being copied and which ones are being referenced? Let's say msg->x and msg->y are they copied or referenced?

I am not familiar with object lifecycle and RAII at this point, could someone please explain to me in Layman's terms what's going on within ROS callbacks when ConstPtr& is used?


Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.