Modify contents of a custom message pointer?

asked 2017-07-08 11:46:23 -0500

MWrock gravatar image

I have a custom message I've created, I want to pass a pointer to this message from one function to another and modify the contents of the message, however ROS doesn't seem to want to allow me to do this. Is there a way to do it without having to pass the message and use the function return to overwrite the original message?

I would imagine something like this:

void change_value(my::custom_message::Ptr &msg){
  msg->value = msg->value + 1;
}
int main(){
  my::custom_message original;
  change_value(&original);
}

Rather than this:

my::custom_message change_value(my::custom_message msg){
  my::custom_message ret;
  ret.value = msg.value + 1;
  return ret;
}
int main(){
  my::custom_message original;
  original = change_value(original);
}
edit retag flag offensive close merge delete

Comments

This reads more like a C++ problem than a ROS problem, but without you telling us why "ROS doesn't seem to want to allow [you] to do this" it's going to be hard to help you.

gvdhoorn gravatar image gvdhoorn  ( 2017-07-08 16:05:48 -0500 )edit