title: accessing protected members of superclass in C++ with templates
body: <p>Why can't a C++ compiler recognize that <code>g()</code> and <code>b</code> are inherited members of <code>Superclass</code> as seen in this code:</p>
  
  <pre><code>template&lt;typename T&gt; struct Superclass {
   protected:
    int b;
    void g() {}
  };
  
  template&lt;typename T&gt; struct Subclass : public Superclass&lt;T&gt; {
    void f() {
      g(); // compiler error: uncategorized
      b = 3; // compiler error: unrecognized
    }
  };
  </code></pre>
  
  <p>If I simplify <code>Subclass</code> and just inherit from <code>Subclass&lt;int&gt;</code> then it compiles.  It also compiles when fully qualifying <code>g()</code> as <code>Superclass&lt;T&gt;::g()</code> and <code>Superclass&lt;T&gt;::b</code>.  I'm using LLVM GCC 4.2.</p>
  
  <p>Note: If I make <code>g()</code> and <code>b</code> public in the superclass it still fails with same error.</p>