C++ 模板 - 没有可行的转换错误

标签 c++ templates point-cloud-library

我现在正在使用 PCL(点云库)处理 C++ 中的模板,我遇到了一些我无法解决的问题(我之前在互联网和 Stack 上搜索过)

我有一个名为 Features 的模板类。

我的 hpp 文件:

#ifndef KeyFeatures_hpp
#define KeyFeatures_hpp

// Declarations and includes

typedef pcl::PointXYZRGB PointTypeRGB;
template<typename FeatureType>
class Features {

public:
    Features(const int typeDescriptor);

 void setDescriptorExtractor(typename  pcl::Feature<PointTypeRGB, FeatureType>::Ptr extractor);

private:
    typename pcl::Feature<PointTypeRGB, FeatureType>::Ptr m_descriptor_extractor;


};

#endif /* Features_hpp */

在 cpp 文件中,我有一个构造函数,它会检查它是什么类型,然后执行一些操作。

template <typename FeatureType>
Features<FeatureType>::Features(const int type){
       //Some code

if (type == DESCRIPTOR_SHOT){
    pcl::SHOTEstimationOMP<PointTypeRGB, pcl::Normal, pcl::SHOT352>* shot = new pcl::SHOTEstimationOMP<PointTypeRGB, pcl::Normal, pcl::SHOT352>;
    shot->setRadiusSearch (0.02f);

    pcl::Feature<PointTypeRGB, pcl::SHOT352>::Ptr descriptor_extractor (shot);
    descriptor_extractor->setSearchMethod (pcl::search::Search<PointTypeRGB>::Ptr (new pcl::search::KdTree<PointTypeRGB>));

    this->m_descriptor_extractor = descriptor_extractor;//ERROR
    setDescriptorExtractor(descriptor_extractor);//ERROR

       // Some code
}

当我尝试填写我的变量成员但没有成功时,错误出现在最后两行。 每次出现如下错误x 10(对应我的10种类型)

error: no matching conversion for functional-style cast from 'const shared_ptr<pcl::Feature<pcl::PointXYZRGB, pcl::SHOT352> >'
to 'this_type' (aka 'shared_ptr<pcl::Feature<pcl::PointXYZRGB, pcl::ShapeContext1980> >')

然而,在我的 cpp 文件的末尾,我放置了所有的模板类。例如:

template class Features<pcl::SHOT352>;

在我的主函数中,我通过使用调用了这个类:

Features<pcl::SHOT352> feature_SHOT(type);

它似乎无法执行转换..

有人可以帮助我吗?

感谢

最佳答案

显然你正在实例化 Features<pcl::ShapeContext1980>所以它的 m_descriptor_extractor类型为 pcl::Feature<pcl::PointXYZRGB, pcl::ShapeContext1980>::Ptr这是shared_ptr<pcl::Feature<pcl::PointXYZRGB, pcl::ShapeContext1980>> .

但在构造函数中您仍在使用 pcl::Feature<pcl::PointXYZRGB, pcl::SHOT352>::Ptr , 即 shared_ptr<pcl::Feature<pcl::PointXYZRGB, pcl::SHOT352>> - 完全不同的类型。

作为旁注,you generally don't implement templates in .cpp files .

关于C++ 模板 - 没有可行的转换错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36174126/

相关文章:

c++ - 为什么我不能使用 getter 访问公共(public)变量?

c++ - 当我尝试输入值时程序崩溃

c++ - decltype 中的表达式是否被执行,或者只是被检查以进行验证?

django:如何在每个模板中显示用户登录?

c++ - 如何积累模板参数包?

c++ - 当内存对齐问题 (AVX) 不在最小上下文中重现时,如何调试它们?

c++ - Boost 编译点云库时出现的问题

c++ - 在 Windows 中查找扬声器输出的当前音量级别

c++ - 3d 到 2d 图像转换 - PointCloud 到 OpenCV 图像 - C++

c++ - 在现代 PC 的 C++ 异常类中避免 std::wstring 数据成员是否有意义?