Hi there.
"qazmlp" <> schrieb im Newsbeitrag
news: m...
> It is advised to have the template implementation inside header files.
> But, Say, I keep the implementation in .C file. Are there any run time
> problems expected out of this or this is simply a link time problem?
>
I'd say it would not work at all!
It is necessary to compile the whole template code with the type of the
template parameter known, otherwise the compiler can not generate the
correct object code and can not check if the template parameter meets all
requirements (like operators etc.)
In other words: You can create an object of a template module and then
use this object code for different instantiations of the template.
One solution to this problem is to place the definition in the .h file and
the implementation in the .cpp file, but then you have to include the
..cpp file from the .h file, exactly the other way round than it is normally
done.
May be confusing if somebody else is looking at the code.
> Also, I would like to confirm whether having the template
> implementation in .h will increase the executable size for any reason
> compared to its size when the implementation is kept in a .C file.
Since the latter is not possible there is nothing to compare against.
However, the size of your executable will be larger since each template
instantiation generates a new class with all the code of the template.
hth
René
=======================================
C++ sources, cross-platform (UNIX and WinTel) and
covering several topics:
http://gemini.futurezone.com