Are your trying to copy the pointer, or are you trying to copy the data itself? Because it looks like you're trying to copy the pointer. You should be able to simply declare the object elsewhere in your program and use the '=' operator without any real fuss.
Take from this thread: https://answers.ros.org/question/1472...
Here's a complete example of copying the actual data:
#include <ros/ros.h>
#include <sensor_msgs/Range.h>
sensor_msgs::Range bar;
myCallbackFunction(const sensor_msgs::Range& foo) {
bar = foo;
ROS_INFO("Data Received: [%f]", bar.range);
}
int main(int argc, char **argv) {
ros::init(argc, argv, "my_node");
ros::NodeHandle _nh;
ros::Subscriber _sub = _nh.subscribe("range_topic", 10, &myCallbackFunction);
ros::spin()
return 1;
}