Yes, there is.
If you put the template code in a .cpp file, what exactly can the compiler do when it compiles the .cpp? It can't
generate code, because it doesn't know the real types. Consider this simple example:
1 2 3
|
template< typename T >
T add( T a, T b )
{ return a + b; }
|
If this code were in a .cpp file, what instructions could the compiler generate? How many different ways will this
function actually be called in the code?
If T is int, then a + b can generate an ADD instruction.
If T is float, then a + b must generate FADD (floating point add) instruction.
If T is std::string, then a + b must call operator+ on std::string.
Etc, etc.
The point is that the compiler can't generate code for the function until it knows what type T is. And if the
function is called with many different T's in the program, then the compiler must generate many different
versions of code for the same function name.