If I have a template function in a seperate compile unit (which produces an object file with suffix .o from the CUDA C compiler NVCC)
lets say we have the definition (implementation)
template<typename T>
void foo(T a){
// something
}
To produce the explicit code in the object file to be able to link to it from another compilation unit I need to explicit instantiate this template (for all template parameters I need) this:
template void foo<double>(double a);
template void foo<float>(double a);
Doing this results in actual code in the object file.
Doing the other thing like:
template<> void foo<double>(double a);
template<> void foo<float>(float a);
Does not produce code in the object file, because this is a full spezialized template declaration. Is this correct?
Also
void foo(double a);
void foo(float a);
does not produce code because this would be a overload declaration ? is this correct?
The question is now, what is the general syntax to make the compiler produce code for a template function or class in a separate compilation unit?