【问题标题】:"<varName> was not declared in this scope" using templates and inheritance in C++“<varName> 未在此范围内声明”在 C++ 中使用模板和继承
【发布时间】:2014-01-08 15:40:53
【问题描述】:

我正在使用 PCL(点云库)。我创建了一个继承自 PCL 模板类 (pcl::SpinImageEstimation) 的类 (myPCL_SI)。我创建了另一个普通类 (myPCL),它创建了一个 myPCL_SI 对象。

我这样做是因为我需要从pcl::SpinIMageEstimation 访问受保护的方法。如果有人知道更好的解决方案,请告诉我。

好的,我的问题是当我尝试创建myPCL_SI 对象时,编译器给了我这个错误:

error: ‘spinImage’ was not declared in this scope
error: template argument 1 is invalid
error: template argument 3 is invalid

我的代码是这个:

myPCL 类(仅我的方法)

void myPCL::calcSpinImage(){

    myPCL_SI<pcl::PointXYZ, pcl::Normal, pcl::Histogram<153>> spinImage;

    // doing more things...
}

myPCL_SI 类(标头)

#ifndef MYPCL_SI_H
#define MYPCL_SI_H

// a lot of includes...

using namespace pcl;

template <typename PointInT, typename PointNT, typename PointOutT>
class myPCL_SI : public SpinImageEstimation<PointInT, PointNT, PointOutT>
{
public:
    myPCL_SI();
    void compute(PointCloud<PointXYZ>::Ptr cloud);

};

#include "mypcl_si.cpp"

#endif // MYPCL_SI_H

myPCL_SI 类 (impl)

template <typename PointInT, typename PointNT, typename PointOutT>
myPCL_SI<PointInT, PointNT, PointOutT>::myPCL_SI()
{

}

非常感谢! :D

【问题讨论】:

    标签: c++ templates inheritance compiler-errors


    【解决方案1】:

    如果您使用的是较旧的编译器,则在153 之后的两个&gt;&gt; 之间需要一个空格。

    Template within template: why "`>>' should be `> >' within a nested template argument list"

    【讨论】:

    • 我花了 2 个小时来解决这个问题,这是他妈的错字。我会哭的:'(。非常感谢!:D:D 很抱歉问这个问题,但我没有找到任何关于它的信息。谢谢!!!!
    猜你喜欢
    • 2011-10-27
    • 1970-01-01
    • 2014-04-05
    • 1970-01-01
    • 2020-03-23
    • 2010-12-17
    • 1970-01-01
    • 2012-02-01
    • 2021-07-17
    相关资源
    最近更新 更多