For specialized template templates, you can explicitly specify template arguments, but you do not need to if the template arguments are output. If you do not specify template arguments, they will be output by the compiler using the same rules as overload resolution. To determine which overload function should be selected, the compiler begins by examining only the primary patterns (which are primarily selected by some kind of magical process). View two available primary templates
template <typename T> void foo(T); template <typename T> void foo(T*);
the latter is the best match for a pointer argument. Once the correct primary template is found, the compiler searches for potential specializations of this primary template. However, your example # 2 is not actually a specialization of a function template that takes a pointer argument, although it does include a pointer argument. If you take the main ad
template <typename T> void foo(T*);
and you replace T with an explicitly specified argument to the int* template, you get
template <> void foo<int*>(int**);
I.e. ad
template <> void foo<int*>(int*);
is something else. You probably just want to lose the pointer when specifying the template argument:
template <> void foo<int>(int*);
source share