title: Overloading c++ template class method
body: <p>Can I overload a template class function in a class that extends its specialization?</p>
  
  <p>I have the following piece of code (I've tried to simplify it to the bare minimum):</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  class X {
   public:
    unsigned test_x() {
      return 1;
    }
  };
  
  class Y {
   public:
    unsigned test_y() {
      return 2;
    }
  };
  
  template &lt;typename T, typename U&gt;
  class A {
  
   public: 
  
    unsigned foo(U i) {
      cout &lt;&lt; "A" &lt;&lt; endl;   
      return i.test_x();
    }
  
    unsigned bar(T i) {
      return foo(i);
    }
  
  };
  
  class B : public A&lt;Y, X&gt; {
   public:
    unsigned foo(Y i) {
      cout &lt;&lt; "B" &lt;&lt; endl;   
      return i.test_y();
    }
  };
  
  int  main() {
  
    B b = B();
    Y y = Y();
    cout &lt;&lt; "Hello: " &lt;&lt; b.bar(y) &lt;&lt; endl;   
    return 0;
  
  }
  </code></pre>
  
  <p>However the compiler produces the following error:</p>
  
  <pre><code>hello.cc: In member function ‘unsigned int A&lt;T, U&gt;::bar(T) [with T = Y, U = X]’:
  hello.cc:47:   instantiated from here
  hello.cc:30: error: no matching function for call to ‘A&lt;Y, X&gt;::foo(Y&amp;)’
  hello.cc:24: note: candidates are: unsigned int A&lt;T, U&gt;::foo(U) [with T = Y, U = X]
  </code></pre>
  
  <p>Basically I would like to overload the function A::foo() in its derived class B.</p>