It makes no difference in this case, but there are cases where it will. Lets look at this sample code
template<class T> // (a)
void f(T);
template<> // (b)
void f<>(int*);
template<class T> // (c)
void f(T*);
int main()
{
int *p;
f(p);
}
When we call f(p);
, what function would you expect to be called? Most people would go with b
, and they would be wrong. The reason for this is because specializations do not apply to overload resolution. They are a special recipe for a template that tells the compiler that if you deduce this type, then stamp out the template this way instead.
So what the compiler does is go through overload resolution and says I can call a
with T
being int*
, or I can call c
with T
being int
. Since the latter is more specialized (T
is narrower), c
wins. This can be very surprising but it makes a lot of sense once you ignore the specialization and just consider the overloads.
Walter E. Brown has a very in depth video about templates and specialization called “C++ Function Templates: How Do They Really Work?” that you should consider watching. It is an hour long, but it is very detailed.