title: Wrong template function deduction
body: <p>Unexpected function deduction is happening in the following program. -</p>
  <p><strong>Case I</strong> -</p>
  <pre><code>template &lt;typename T, typename&gt;
  void foo(T x, int) {
      cout &lt;&lt; &quot;In int foo\n&quot;;
  }
  
  template &lt;typename T&gt;
  void foo(T x, char) {
      cout &lt;&lt; &quot;In char foo\n&quot;;
  }
  
  int main() {
      string s = &quot;Hello World&quot;;
      foo(s, (int) 1);
  }
  </code></pre>
  <p>Output</p>
  <pre><code>In char foo
  </code></pre>
  <p><strong>Case II</strong> -</p>
  <pre><code>template &lt;typename T&gt;
  void foo(T x, int) {
      cout &lt;&lt; &quot;In int foo\n&quot;;
  }
  
  template &lt;typename T&gt;
  void foo(T x, char) {
      cout &lt;&lt; &quot;In char foo\n&quot;;
  }
  
  int main() {
      string s = &quot;Hello World&quot;;
      foo(s, (int) 1);
  }
  </code></pre>
  <p>Output</p>
  <pre><code>In int foo
  </code></pre>
  <p>For case II, I just removed the last template parameter typename from the first function. Could someone please explain what's happening here?</p>