Template function overloading in C++
<p>I have the following definition.</p>

<pre><code>using namespace std;

template &lt;typename T&gt;
void foo(const T &amp;s) {
    cout &lt;&lt; 1;
}

template &lt;typename T&gt;
void foo(const T *s) {
    cout &lt;&lt; 2;
}

int main(int argc, const char * argv[]) {
    char str[] =  "ss";
    char *s = str;
    foo(s);

    return 0;
}
</code></pre>

<p>Then it outputs</p>

<pre><code>1
</code></pre>

<p>From my understanding, both versions have to go through a const conversion. Then <code>void foo(const T *s)</code> is more specialized and should be invoked. However the compiler chose <code>void foo(const T&amp; s)</code>. What is the explanation?</p>