How does function template deduce types with const qualifier?
<p>I have the following code with outputs. I have two questions.</p>

<p>1) foo1 &lt; double, char* >(a,b); is not able to compile by gcc 4.1.2.
    It cannot instantiate it.</p>

<p>2) foo1(a,b); outputs AB, while foo(a,b) can output Ac. Is it because of the const qualifier?</p>

<p>Code:</p>

<pre><code>#include &lt;iostream&gt;

template&lt;typename A, typename B&gt;
class C {
public:
    void operator()(A a, B b) {
        std::cout &lt;&lt; "AB" &lt;&lt; std::endl;
    }
};

template&lt;typename A&gt;
class C&lt;A, const char*&gt; {
public:
    void operator()(A a, const char* b);
};

template&lt;typename A&gt;
void C&lt;A, const char*&gt;::operator()(A a, const char* b) {
    std::cout &lt;&lt; "Ac" &lt;&lt; std::endl;
}

template&lt;typename A, typename B&gt;
void foo(A a, B b) {
    C&lt;A,B&gt;()(a,b);
}

template&lt;typename A, typename B&gt;
class C1 {
public:
    void operator()(A a, const B b) {
        std::cout &lt;&lt; "AB" &lt;&lt; std::endl;
    }
};

template&lt;typename A&gt;
class C1&lt;A, char*&gt; {
public:
    void operator()(A a, const char* b);
};

template&lt;typename A&gt;
void C1&lt;A, char*&gt;::operator()(A a, const char* b) {
    std::cout &lt;&lt; "Ac" &lt;&lt; std::endl;
}

template&lt;typename A, typename B&gt;
void foo1(A a, B b) {
    C1&lt;A,B&gt;()(a,b);
}

int main() {
    double a = 0;
    const char *b;
    C&lt;double, const char*&gt;()(a,b);
    foo&lt;double, const char*&gt;(a,b);
    foo(a,b);

    C1&lt;double, char*&gt;()(a,b);
    //foo1&lt;double, char*&gt;(a,b); 
    foo1(a,b);

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

<p>Outputs:</p>

<pre><code>Ac
Ac
Ac
Ac
AB
</code></pre>