Why will i use explicit instantiation of a function template, for a type? If I do not use explicit instantiation of the function, the template is used to create the necessary function then what is the use of explicit instantiation?
template <class Any>
void Swap (Any &, Any &);
// template prototype
template <> void Swap<job>(job &, job &);
// explicit specialization for job
int main(void)
{
template void Swap<char>(char &, char &);
// explicit instantiation for char
short a, b;
Swap(a,b);
// implicit template instantiation for short
job n, m;
Swap(n, m);
// use explicit specialization for job
char g, h;
Swap(g, h);
// use explicit template instantiation for char
}
In the above eg. explicit instantiation is done for char type. What is the use of this?? If the compiler can make use of the template to make a fn for char type.
If there are any refrences that can help me clear my concept, pls do include those.