Is there a way to write the implementations of template functions (or methods of a template class) in .cpp?
It's making my header very ugly.
If I just move them to .cpp, I get linker errors, as expected.
Thanks
Printable View
Is there a way to write the implementations of template functions (or methods of a template class) in .cpp?
It's making my header very ugly.
If I just move them to .cpp, I get linker errors, as expected.
Thanks
The way I deal with this is to break the template header into two files, for instance Template.h and Template_impl.h, put the implementations in Template_impl.h, then include the implementation file at the end of the main header.
In some cases I've seen people put the implementation in a .cpp and then include the .cpp from the main header. I'm guilty of it, but on the scale of evil it doesn't rank very high IMHO.
You can write the function template definition in a source file, then include that source file in the header. Another file extension, e.g., .ipp, would typically be used in order to avoid confusing such a "to be included" source file with one that is supposed to be compiled separately.
Thanks.
That sounds good.