"aaragon" <[EMAIL PROTECTED]> writes: > I'm using the g++ compiler, and I run into a problem when I try to > separate the declaration in the .h file from the implementation in the > .cpp file. It seems that when I do this, I have linking problems (only > when I use templates in the declarations). Does anyone know why is > this?
Because gcc doesn't support external templates (few (if any) other compilers do). Some compilers play tricks: when you '#include "foo.h"' which declares templates, they "automagically" look for foo.cpp, and include it in the current compilation unit, saving resulting instantiated methods in a template "repository". All such schemes (in my experience) are buggy and eventually cause extreme pain, when partial rebuilds fail to link, because repository is not updated correctly under some conditions. On ELF platforms none of this trickery is necessary anyway, because template bodies are put into linkonce sections, so final executable contains only one copy of the instantiated method (i.e. you don't get code bloat). > I ended up compiling only the .cpp files (which have an #include > "respective_file.h" only) and putting all the implementation details in > the .h files. That's the most portable approach. Another alternative is to manually manage instantiation via explicit instantiation requests. Cheers, -- In order to understand recursion you must first understand recursion. Remove /-nsp/ for email. _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus