title: C++ template class and inheritance
body: <blockquote>
    <p><strong>Possible Duplicates:</strong><br>
    <strong>[FAQ]</strong> <a href="https://stackoverflow.com/questions/1239908/why-doesnt-a-derived-template-class-have-access-to-a-base-template-class-identi">Why doesn't a derived template class have access to a base template class' identifiers?</a>
    <a href="https://stackoverflow.com/questions/1813671/problem-with-protected-fields-in-base-class-in-c">Problem with protected fields in base class in c++</a><br>
    <a href="https://stackoverflow.com/questions/4210108/cannot-access-data-member-in-a-class-template">cannot access data member in a class template</a>  </p>
  </blockquote>
  
  
  
  <p>Following code gives me compilation error. What is wrong?</p>
  
  <pre><code>struct Base {
     int amount;
  };
  
  template&lt;class T&gt; struct D1 : public Base {
  };
  
  template&lt;class T&gt;
  struct D2 : D1&lt;T&gt; {
    void foo() { amount=amount*2; /* I am trying to access base class data member */ };
  };
  
  int main() {
    D2&lt;int&gt; data;
  };
  
  
  test.cpp: In member function 'void D2&lt;T&gt;::foo()':
  test.cpp:11: error: 'amount' was not declared in this scope
  </code></pre>
  
  <p>How to fix this?</p>
  
  <p>thanks</p>