title: Casting to a ConstPtr object using const_cast
body: <p>Recently, I have come across a dilemma in my project.  I can either create a separate object of type pcl::PointCloud::ConstPtr and pass to it a point cloud that is identical to it except mutable, or I can try to cast the mutable point cloud to a ConstPtr point cloud.  I am trying to use const cast to cast the mutable point cloud to a format where it is accepted by several functions which only accept pointClouds which are ConstPtr's.  This is the cast I perform:</p>
  
  <pre><code>pcl::visualization::PointCloudColorHandlerRGBField&lt;pcl::PointXYZRGB&gt; rgbHandler(const_cast&lt;pcl::PointCloud&lt;pcl::PointXYZRGB&gt;::ConstPtr &gt;(&amp;cloud));
  </code></pre>
  
  <p>but an error is thrown in terminal</p>
  
  <pre><code>error: const_cast to
        'pcl::PointCloud&lt;pcl::PointXYZRGB&gt;::ConstPtr' (aka 'shared_ptr&lt;const
        PointCloud&lt;pcl::PointXYZRGB&gt; &gt;'), which is not a reference,
        pointer-to-object, or pointer-to-data-member
    ...const_cast&lt;pcl::PointCloud&lt;pcl::PointXYZRGB&gt;::ConstPtr &gt;(&amp;cloud));
  </code></pre>
  
  <p>which is strange because cloud is declared with a type of pcl::PointCloud here:</p>
  
  <pre><code>pcl::PointCloud&lt;pcl::PointXYZRGB&gt; cloud;
  </code></pre>
  
  <p>So why doesn't this const cast work?  What would make it work?</p>