I am a little confused when one should inline specializations. From this question it gets clear that every specialization must be inlined to avoid duplicate symbol errors. But what if I want to have a declaration of the specialization first, how would that change things?
If we consider this example:
template<typename T>
class myClass
{
public:
static void myPrint(T myVal);
}
#include "declarations.hpp"
//-----------------------------------------------
//declarations.hpp
template<typename T>
void myClass<T>::myPrint(T myVal)
{
cout << "printing unknown type " << myVal;
}
template <>
void myClass<int>::myPrint(int myVal); //inline here or in definition?
template <>
void myClass<float>::myPrint(float myVal); //inline here or in definition?
//-----------------------------------------------
//some_file_that_includes_myClass_header.cpp
template <>
void myClass<int>::myPrint(int myVal) //inline or no inline?
{
cout << "printing int " << myVal;
}
//-----------------------------------------------
//some_other_file_that_includes_myClass_header.cpp
template <>
void myClass<float>::myPrint(float myVal) //inline or no inline?
{
cout << "printing float " << myVal;
}
What would be the correct way to do this, and why?