Ask Your Question

Revision history [back]

For reference, ImagePtr and ImageConstPtr are defined as:

typedef boost::shared_ptr< ::sensor_msgs::Image> ImagePtr;
typedef boost::shared_ptr< ::sensor_msgs::Image const> ImageConstPtr;

The quickest legal solution would be to create an ImageConstPtr with a null deleter, so that when the shared_ptr is destructed, it doesn't try to deallocate the memory. You would also have to be careful that the shared_ptr doesn't outlive your source_image object.

ImageConstPtr image_pointer(*source_image, boost::null_deleter());

However, this is not great. The best thing to do would be to initialize your source_image object as an ImagePtr in the first place, and simply pass it to the function expecting an ImageConstPtr.

For reference, ImagePtr and ImageConstPtr are defined as:

typedef boost::shared_ptr< ::sensor_msgs::Image> ImagePtr;
typedef boost::shared_ptr< ::sensor_msgs::Image const> ImageConstPtr;

The quickest legal solution would be to create an ImageConstPtr with a null deleter, so that when the shared_ptr is destructed, it doesn't try to deallocate the memory. You would also have to be careful that the shared_ptr doesn't outlive your source_image object.

ImageConstPtr image_pointer(*source_image, boost::null_deleter());

However, this is not great. by any means the 'right way'. The best thing to do would be to initialize your source_image object as an ImagePtr in the first place, and simply pass it to the function expecting an ImageConstPtr.