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

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

我有一些代码如下所示:

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;

void
BuildMeshFromDepthImage()
{
    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
}

知道为什么这不起作用吗? P.S。此代码适用于 VS2010,但不适用于 GCC4.9。会不会是因为 PCL 库版本不同?

来自pcl::PointCloud< PointT > Class Template Reference

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

Boost.SharedPtr

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

这就是你需要的:

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

对于 C++11 或更高版本,您可以使用:

auto t= pointCloud->points[i];