That's not a partial specialization (there are no template parameters left un-specialized) it's an explicit specialization.
Templates must be visible to the code that uses them, if you don't declare the specialization in the header file then code that tries to call A::func
with a string
will instantiate the primary template (the one for numbers) and use that, because they don't know the `string specialization even exists.
So you must (at least) declare the specialization in the header in order for it to be usable outsde the .cpp
file:
template<>
void A::func(std::string t);
However your alternative using an overload is simpler and is perfectly acceptable. It works because the overload for string
is declared in the header, so code that calls it knows which function to call.