Access derived template class of a template class

I'm having a problem inheriting data members from a base template class.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
template<class T>
   class DepthLayers
{
public:
   int test;

   DepthLayers():
      test(0)
   {

   }
};

template<class T>
   class ListLayers: public DepthLayers< list<T> >
{
public:
   ListLayers()
   {
      test = 5;  //Errors here
   }
};

Error: |error: 'test' was not declared in this scope|

@"Unexpectedly made a recognized C++ template formula.
(Curiously recurring template pattern)
http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern"
Ops it isn't this. :P
Last edited on
Don't think this is a Curiously Tecurring Template (CRT) pattern
In this case the CRT would be
1
2
template<class T>
   class ListLayers: public DepthLayers< ListLayers<T> >


Anway, when it comes to templates - the compiler is not under any obligation to recognize unqualified variable names from the base class when they are referenced in the derived class as you have done above.

But - Microsoft Visual C++ will allow it, but not GCC.
try this->test =5;

or you can do:
DepthLayers< list<T> >::test = 5
Last edited on
Actually what you suggested "this->test =5;" worked in GCC!!

Thankyou!

And the second one you suggested, wouldn't that only work if test was static?
I meant that the way your original post was written MSVC would accept it but GCC won't - (GCC being tecnically correct to the c++ standard but MSVC being forgiving and understanding exactly what you were trying to do).
Last edited on
Topic archived. No new replies allowed.