title: Overloading reference vs const reference
body: <p>I have the following code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  template &lt;typename T&gt;
  void f(T&amp; x)        
  {
      std::cout &lt;&lt; "f(T&amp; )" &lt;&lt; std::endl; 
  }
  
  template &lt;typename T&gt;
  void f(const T&amp; x) 
  { 
      std::cout &lt;&lt; "f(const T&amp; )" &lt;&lt; std::endl; 
  }
  
  int main() 
  {
      int a = 0;
      const float b = 1.1;
  
      f(a); // call f(T&amp;)
      f(b); // call f(const T&amp;)
  }
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>f(T&amp; )
  f(const T&amp; )
  </code></pre>
  
  <p>My question is: how does the compiler know which function to call? If I remove the references from the function definitions then I get an "ambiguous call" type of error, i.e. <code>error: redefinition of 'f'</code>. For me it looks like <code>f(T&amp;)</code> can be equally well used for both calls, why is the <code>const</code> version unambiguously called for <code>f(b)</code>?</p>