本文介绍了在模板化嵌套和继承的类中未检测到变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a nested and inherited structure like this.

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变量时,编译器看不到它有这个变量。

And when I want to visit the bounds variable in OcHull, compiler doesn't see it has this variable.

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

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

Could you please tell me why it doesn't see bounds ?

推荐答案

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

You need to say this->bounds or Octree<U, T, _Prd>::bounds. In C++, when a class template inherits from another class template, the template base class is not instantiated during the first compilation pass, so the inherited members must be accessed with an explicit qualifier.

有关更详细的解释,请参阅。

See this answer for a more elaborate explanation.

这篇关于在模板化嵌套和继承的类中未检测到变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 23:21