John Yang John Yang - 1 year ago 181
C++ Question

error: no type named 'value_type' in 'class boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZ> >'

I have some code looks like the following:

typedef pcl::PointXYZRGB pcl_ColorPointType;
typedef pcl::PointXYZ pcl_PointType;
typedef pcl::PointCloud<pcl_PointType> pcl_XYZPointCloudType;
typedef pcl::PointCloud<pcl_ColorPointType> pcl_ColorPointCloudType;
typedef pcl_XYZPointCloudType::Ptr pcl_XYZPointCloudPtrType;
typedef pcl_ColorPointCloudType::Ptr pcl_ColorPointCloudPtrType;

pcl_XYZPointCloudConstPtrType pointCloud = BuildPurePointCloudFromDepthImage( ); // assume BuildPurePointCloudFromDepthImage function exists
BuildMeshFromPointCloud<pcl_XYZPointCloudConstPtrType>( pointCloud );

template<typename T_pclPtr>
void BuildMeshFromPointCloud(const T_pclPtr &pointCloud )
// some code

// error: no type named 'value_type'
const typename T_pclPtr::value_type::PointType& pt = pointCloud->points[i];

// some code

Any idea why this does not work? P.S. This code works under VS2010 but not with GCC4.9. Could that be because of different version of PCL library?

Answer Source

From pcl::PointCloud< PointT > Class Template Reference

typedef boost::shared_ptr< PointCloud< PointT > >   Ptr

and Boost.SharedPtr

element_type is T when T is not an array type, and U when T is U[] or U[N].

This is what you need:

typename T_pclPtr::element_type::PointType& t= pointCloud->points[i];

For C++11 or later, you can use this:

auto t= pointCloud->points[i];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download