ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

What's the difference between PointCloudConstPtr and PointCloud::ConstPtr

asked 2018-06-07 11:21:23 -0500

vpradeep gravatar image

In subscriber callbacks our software stack uses a mixture of two function signatures. In the case of subscribing to a sensor_msgs::PointCloud, we use the following two signatures:

  1. void callback(const sensor_msgs::PointCloud::ConstPtr& msg)
  2. void callback(const sensor_msgs::PointCloudConstPtr& msg)

These are both defined in the autogenerated header PointCloud.h

template <class ContainerAllocator>
struct PointCloud_
  // ---- Snip ----
  typedef boost::shared_ptr< ::sensor_msgs::PointCloud_<ContainerAllocator> const> ConstPtr;
typedef ::sensor_msgs::PointCloud_<std::allocator<void> > PointCloud;

typedef boost::shared_ptr< ::sensor_msgs::PointCloud > PointCloudPtr;
typedef boost::shared_ptr< ::sensor_msgs::PointCloud const> PointCloudConstPtr;

Expanding the typedefs myself, I get the following

  1. sensor_msgs::PointCloud::ConstPtr

    boost::shared_ptr< ::sensor_msgs::PointCloud_<ContainerAllocator> const>

  2. sensor_msgs::PointCloudConstPtr
    boost::shared_ptr< ::sensor_msgs::PointCloud_<std::allocator<void> > const>

It's not clear to me what ContainerAllocator gets set to in case 1, and I'm also not sure what the purpose of ContainerAllocater is. Why would I choose one incantation over the other?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-06-07 20:57:59 -0500

ahendrix gravatar image

These are the same.

PointCloud_::ConstPtr is templated on the ContainerAllocator, but the PointCloud typedef specifies a default container allocator of std::allocator<void>, so they're the same.

I'm not sure why there are two aliases for the same symbol.

edit flag offensive delete link more


Makes sense. You're right that PointCloud::ConstPtr uses std::allocator<void>, and hence they're the same. I guess I just tripped myself up when attempting to expand the typedefs by hand. Thanks for the clarification.

vpradeep gravatar image vpradeep  ( 2018-06-07 22:06:19 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2018-06-07 11:21:23 -0500

Seen: 973 times

Last updated: Jun 07 '18