The following code is in a .h file (with include guards)
template<typename T1, typename T2> // a
void func(T1 const &t1, T2 const &t2)
{
std::cout << "\nbase template";
}
template<> // b
inline void func<int, int>(int const &t1, int const &t2)
{
std::cout << "\nspecialization for integers";
}
When removing the inline keyword from (b) the following code (called from a .cpp that includes the .h) won't compile
func<int, int>(1, 2);
emmiting a linker error " error LNK2005: "void __cdecl func(int const &,int const &)" (??$func@HH@@YAXABH0@Z) already defined in ConsoleApplication1.obj "
Why is this happening ?
EDIT:
So since they are definitions (answered by Luchian Grigore), do explicit specializations imply explicit instantiation or is this compiler specific?