Skip the first call to foo(x) .
int cannot be written as a pointer, unable to output the parameter, the following
void foo(int* l);
Cannot convert int to int* implicitly, then
template<typename T> void foo(T t);
This seems like a good match, for example, remember 2). Further
template<> void foo<int*>(int* l);
Cannot convert int to int* implicitly, then
template<typename T> void foo(T* l)
So the only possible match is 2), and therefore template<T> foo(T) is the way out.
The second call, foo(&x) .
void foo(int* l);
A function without a pattern that perfectly matches type x . Remember this one.
template<typename T> void foo(T t);
Good coincidence! But the previous is even better, the next
template<> void foo<int*>(int* l);
Oh, the specialization of the previous template that exactly matches the type is better, but 1) it still matches better. Further
template<typename T> void foo(T* l)
Better than specialization, a template without, but not a non-template, beats.
So, at the end, a function without a template is called. Non-templates are always better than templates.