c++ - 错误 : no type named 'value_type' in 'class boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZ>>'

标签 c++ templates point-cloud-library

我有一些代码如下所示:

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
}

知道为什么这不起作用吗?附言此代码适用于 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];

关于c++ - 错误 : no type named 'value_type' in 'class boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZ>>' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40415403/

相关文章:

c++ - 一个模板专门化多个类

c++ - 从共享指针转换为共享指针到 const

c++ - 函数重载 : empty parameter list vs parameter pack

c++ - PCL : Failed to find match for field 'rgba'

c++ - PCL : X and Y values are changed when pcd file is loaded by PCL library

c++ - 带有 Visual Studio 2017 的点云库

c++ - 用 FFmpeg 编写多线程视频和音频数据包

c++ - 动态创建typedef

c++ - 从模板类继承和调用模板函数时出错

c++ - 模板类函数语法的模板类参数