   Template inheritance problem
  When I try to inherit from a template with a variable type I get an error.#include <iostream>using namespace std;template<class T>class parent{ public:    parent()    {    number=5;    }    int number;};template<class T>class child: public parent<T>{ public:    int getnum()    {  return number; //<--- generates error    }};int main(){    child<int> c;    cout<<c.getnum();    getchar();    return 0;}That gives me a 'number undeclared' error but if I changed "public parent<T>" to "public parent<int>" it will work just fine. Im trying to make a base class for afew container classes so I wont know the type untill runtime.   
  What compiler are you using? That code works fine for me, and prints "5" on the console.   ;  Also, maybe you could post the exact error as generated by the compiler.   ;  Ive tried this in dev-c++ and code::blocks. heres my errors: C:\Documents and Settings\Desktop\Untitled1.cpp In member function `int child<T>::getnum()': 21 C:\Documents and Settings\Desktop\Untitled1.cpp `number' undeclared (first use this function)   (Each undeclared identifier is reported only once for each function it appears in.)   ;  This will solve the error:int getnum(){    return parent<T>::number;}Unfortunately I dont know the technical explanation to why you get this error.As far as I know, the client class should be able to understand that the number variable resides in the parent<T> class...   ;  Ok, thanks.   ;  Hm, apparently that's what the ISO/ANCI C++ standard dictates and the G++ compiler is more close to it that the past: link (see the code below the line "In a template definition, unqualified names will no longer find members of a dependent base"):Quote:In a template definition, unqualified names will no longer find members of a dependent base.For example,   template <typename T> struct B {  int m;  int n;  int f ();  int g ();};int n;int g ();template <typename T> struct C : B<T> {  void g ()  {    m = 0; // error    f ();  // error    n = 0; // ::n is modified    g ();  // ::g is called  }};You must make the names dependent by prefixing them with this->. Here is the correcteddefinition of C<T>::g,template <typename T> void C<T>::g (){  this->m = 0;  this->f ();  this->n = 0  this->g ();}Apparently, the easiest way is just qualify members with "this->". I can't think though any reasons on why this is needed especially for templates.   ;  I don't have a compiler to check it (I only have VS), but you can also just "use" the dependent name, like this:#include <iostream>using namespace std;template<class T>class parent{ public:    parent()    {    number=5;    }    int number;};template<class T>class child: public parent<T>{ public:    using parent<T>::number; // NOTICE THIS    int getnum()    {  return number;    }};int main(){    child<int> c;    cout<<c.getnum();    getchar();    return 0;}I haven't use this in some time, but I believe this is how it works.   