3

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 ;

};

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) ; 

        ...


    }
}

Error is

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

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

tomriddle_1234
  • 3,145
  • 6
  • 41
  • 71
  • @WhozCraig, I think Hull::OcHull should inherit the private members from Octree, keeping the private attribute. Why you have shock by seeing Octree's members are private ? I think the data should be touched out of the class , is there a better reason not to do so ? – tomriddle_1234 Dec 20 '12 at 00:34

2 Answers2

4

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.

Community
  • 1
  • 1
Charles Salvia
  • 52,325
  • 13
  • 128
  • 140
3

Base classes that depend on template parameters are not considered by unqualified name lookup.

You are using unqualified name bounds. And the base class Octree<U, T, _Prd> depends on template parameters. So, the contents of the base class is not considered by the compiler and bounds is not found.

You can solve it in several ways.

  1. Use a qualified name when referring to bounds

    Octree<U, T, _Prd>::bounds
    
  2. Access bounds through this->

    this->bounds
    
  3. Add a using declaration of bounds to the derived class

    class OcHull: public Octree<U, T, _Prd>
    {    
      using Octree<U, T, _Prd>::bounds;
      ...
    
AnT stands with Russia
  • 312,472
  • 42
  • 525
  • 765