I've read that the body of a template function must be included in the file which actually uses it (i.e., the decleration isn't enough).
Suppose that I define a template function in a header file:
//someheader.h
#ifndef SOME_H
#define SOME_H
template<class T>
void MyTemplateFunc(T *In, ...)
{
//definitions here
}
#endif
I can actually use it in two different cpp files:
//file1.cpp
#include "someheader.h"
void f1()
{
//some code
MyTemplateFunc<int>(Some_int_Pointer);//use template here
}
and
//file2.cpp
#include "someheader.h"
void f2()
{
//some code
MyTemplateFunc<float>(Some_float_Pointer);//use template here
}
Now, I am not complaining (just trying to understand) but how come I am not getting compiling/linking error in this case?. Since the double inclusion guard will cause "someheader.h" to be included only in one of the cpp files which in turn will cause the other cpp file to complain that he can't "see" the template definition.
What am I missing here?
Thanks
Benny