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
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.
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
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.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Thanks.
That sounds good.