c++ - 在模板化的嵌套和继承类中未检测到变量

标签 c++ class templates inheritance

我有一个像这样的嵌套和继承结构。

template <typename U, typename T, typename _Prd = equal_to<T> >
class Octree
{
...
private :
    BBox<T,3,_Prd> bounds ;

    void SplitNode() ;
    virtual bool isSplit () ;
...
};


template <typename U, typename T, typename _Prd = equal_to<T> >
class Hull
{
    ...
    //nest the octree class here

    class OcHull: public Octree<U, T, _Prd>
    {
        bool isSplit () ;  
    };

    OcHull * GetOcHull() const ;

private:

    OcHull * hullstructure ;

};

当我想访问 OcHull 中的 bounds 变量时,编译器看不到它有这个变量。

template <typename U, typename T, typename _Prd>
bool Hull<U,T,_Prd>::OcHull::isSplit()
{
    assert(typeid(double) == typeid(T)) ;
    // for each possible view of currect cell

    for (size_t i = 0 ; i < camera_array.size() ; ++i)
    {
        //project centre of the cell

        // bounds is not detected. bound is meant to be inherited from BBox<T,3,_Prd> bounds ; above

        Vec<double,2> projectedP = camera_array[i].projectToCamPlane(bounds.centre) ; 

        ...


    }
}

错误是

Hull.hpp:84: error: ‘bounds’ was not declared in this scope

你能告诉我为什么它看不到边界吗?

最佳答案

你需要说this->boundsOctree<U, T, _Prd>::bounds .在 C++ 中,当一个类模板继承自另一个类模板时,模板基类不会在第一次编译过程中实例化,因此必须使用显式限定符访问继承的成员。

参见 this answer以获得更详细的解释。

关于c++ - 在模板化的嵌套和继承类中未检测到变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13963215/

相关文章:

c++ - OpenCV - 缺少调试 DLL 库

c++ - 获取对 unique_ptr<> 数组项的引用?

c++ - "generalized"有限状态机实现

python - 没有模型的 Django.contrib.flatpages

css - 每次在 Meteor 中渲染时脉冲模板

c++ - 如何使用线程登录文件

c++ - 如何诊断奇怪的竞争条件错误?

c++ - 一行类定义?

月份对象的 Java 类

python - 比较两个对象时超出最大递归深度