C++ Namespace Template Functions
C++, Templates
If you define a C++ template function in a namespace, the function definition needs to go in the header - not the .cpp
file.
Example
You could also put the implementation in .cpp and include this file from within the header file.
Why?
Template functions are not real functions - they are turned into a real function by the compiler when it encounters a use of the function.
This means that the template definition needs to be in the same scope as the call to the function. If the function is called in main.cpp
and utilities.h
is included in this file, then the template must be defined in utilities.h
.
References
comments powered by Disqus