title: C++ template: Derived class cannot resolute Base class function unless using "this->"
body: <p>This code doesn't compile:</p>
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  template&lt;class T&gt;struct Base {
      void f(int) { cout &lt;&lt; &quot;Base::f() int\n&quot;; }
  };
  template&lt;class T&gt;struct Derived:Base&lt;T&gt; {
      void g(int i) { f(i); } // should be this-&gt;f(i) to pass compile
  };
  int main(){
      Derived&lt;char&gt; obj;
      obj.g(1); // cfunction short
      return 0;
  }
  </code></pre>
  <p>I googled and search on stackoverflow, it says that in the error-line, I should use write either</p>
  <pre><code>void g(int i) { this-&gt;f(i); }
  </code></pre>
  <p>or</p>
  <pre><code>void g(int i) { Base&lt;T&gt;::f(i); }
  </code></pre>
  <p>Yes, they work. I tried none-template version, doesn't need this complex qualifier. As long as both <code>f()</code> and <code>g()</code> doesn't use any template type parameter, I didn't think of a rule on template deduction upon these 2 functions.</p>
  <p>Is this some hidden rule behind template resolution that I should add extra qualifier, and why my original code fail to compile?</p>