title: Template classes vs Private inheritance
body: <p>Why would some compilers insist on qualifying members public members of template base class while the not requiring the same for non-template class? Please look at the following code listings:</p>
  
  <p><strong>Template class:</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  template &lt;class T&gt;
  class TestImpl {
  public: // It wont make a difference even if we use a protected access specifier here
      size_t vval_;
      TestImpl(size_t val = 0) : vval_(val) { }
  };
  
  template &lt;class T&gt;
  class Test : public TestImpl&lt;T&gt; {
  public:
      Test(size_t val) : TestImpl&lt;T&gt;(val) {
          cout &lt;&lt; "vval_ : " &lt;&lt; vval_ &lt;&lt; endl; // Error: vval_ was not declared in this scope
          //! cout &lt;&lt; "vval_ : " &lt;&lt; TestImpl&lt;T&gt;::vval_ &lt;&lt; endl; // this works, obviously
      }
  };
  
  int main() {
      Test&lt;int&gt; test1(7);
  
      return 0;
  }
  </code></pre>
  
  <p><strong>Non-template class:</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  class TestImpl {
  public: // It wont make a difference even if we use a protected access specifier here
      TestImpl(size_t val = 0) : vval_(val) {}
      size_t vval_;
  };
  
  class Test : public TestImpl {
  public:
      Test(size_t val) : TestImpl(val) {
          cout &lt;&lt; "vval_ : " &lt;&lt; vval_ &lt;&lt; endl;
      }
  };
  
  int main() {
      Test test1(7);
  
      return 0;
  }
  </code></pre>
  
  <p>The significant difference between the above code listings is that while the first listing uses template classes, the second one doesn't. </p>
  
  <p>Now, both listings will compile fine with <strong>Microsoft's Visual Studio Compiler</strong> (cl) but the first listing <strong>WONT</strong> compile with both the <strong>Digital Mars Compiler</strong> (dmc) and <strong>Minimalist GNU for Windows</strong> (MinGW - g++) compiler. I will get an error like "vval_ was not declared in the scope" - an error I obviously understand what it means. </p>
  
  <p>If I qualify access to the <strong>TestImpl</strong>'s public variable <strong>vval_</strong> using <strong>TestImpl&lt;T&gt;::vval_</strong> the code works. In the second listing, the compilers do not complain when the derived class accesses the base class' <strong>vval_</strong> variable without qualifying it.</p>
  
  <p>With regard to the two compilers and possibly others, my question would be why I should be able to directly access (without qualifying) <strong>vval_</strong> variable directly from a <strong>non-template class inheriting from a non-template class</strong>, while I cant do the same from <strong>a template class inheriting from a template class</strong>?</p>