title: C++ - invalid use of undefined type ... - declaration of `class
body: <p>I have classes SuperClass and Subclass, where SubClass is inheriting from SuperClass.</p>
  
  <p>In SuperClass I have a constant property who's values depends on the SubClass using it. Howerver I need it to be declared in SuperClass as there are some other methods in SuperClass using it as well, but I need to initalize it in SubClass as the value of the constant changes depending on the SubClass type instantiated.</p>
  
  <p>From a <a href="https://stackoverflow.com/questions/18467376/c-virtual-variable-in-inheritance-class-hierarchy">previous question on SO</a>, I know the best solution to this is using a trait class. However using such a solution would involve massive changes to my code. Therefore, I have chosen the approach here shown.</p>
  
  <p><strong>SuperClass.h</strong></p>
  
  <pre><code>#ifndef SUPERCLASS_H
  #define SUPERCLASS_H
  
  
  #include &lt;string&gt;
  
  template &lt;class T, class P&gt;
  class SuperClass
  {
        public:
  
         typedef T type;
         typedef P position;
  
         static const position NULLPOSITION;
  
  };
  
  #endif
  </code></pre>
  
  <p><strong>SubClass.h</strong></p>
  
  <pre><code>#ifndef SUBCLASS_H
  #define SUBCLASS_H
  
  #include &lt;string&gt;
  #include "SuperClass.h"
  
  
  template &lt;class T&gt;
  class SubClass:public SuperClass&lt;T,int&gt;
  {
  
  };
  
  template&lt;class T&gt;
  const typename SuperClass&lt;T,int&gt;::position SuperClass&lt;T,int&gt;::NULLPOSITION=0;
  
  #endif
  </code></pre>
  
  <p><strong>main.cpp</strong></p>
  
  <pre><code>#include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  #include "SubClass.h"
  
  using namespace std;
  
  int main(int argc, char *argv[])
  {
      SubClass&lt;int&gt; subClass;
  
      system("PAUSE");
      return EXIT_SUCCESS;
  }
  </code></pre>
  
  <p>On compiling I get </p>
  
  <pre><code>invalid use of undefined type `class SuperClass&lt;T, int&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>declaration of `class SuperClass&lt;T, int&gt;
  </code></pre>
  
  <p>errors.
  What might be the issue?</p>