Noob <
no...@nono.com> wrote in news:lut2m8$ihb$
1...@dont-email.me:
> Thank you very much. There's -a lot- of useful information there.
>
> In my case, would you recommend me to move the definition of the
> template to the header file or to do the second solution shown here:
>
>
http://www.parashift.com/c++-faq/separate-template-fn-defn-from-
decl.html
>
> The former seems easy enough but I wouldn't like to make a habit
> of it if it happens to be a source of future complications.
[for the record: the second solution means explicit instantiation of
templates in a single source file]
In software development (and probably especially with C++) you will
notice in time that complexity tends to increase "by itself" and fighting
with the complexity is the most important thing to do. So the rule of
thumb is to always prefer the simplest solution if possible, and here the
first solution (putting all templates in header files) is definitely the
simplest one and means least headaches to write and maintain. Many
template libraries are actually header-only (including many parts of
STL), so the compilers are ready to cope with them.
Many people see that the first solution actually has several advantages:
no need to guess which instantiations are required by the program, plus
better optimization possibilities for the compiler (as the function
definitions are visible inline). The only downside is that the compiling
times might become larger, to fight this one can just keep the header
files concsice and include them only in source files which actually need
them.
I would suggest to use the second solution (explicit instantiation in a
source file) only when you are experienced enough to decide this is a
better solution.
Cheers
Paavo