Topic: Where do templates go?
Author: dechc00@tohi.DMI.USherb.Ca (CHRISTIAN DECHAMPLAIN)
Date: Fri, 13 Nov 1992 17:25:06 GMT Raw View
Thanks to those who answered my original question.
With g++ it seems that every implamentation file with a template declaration
needs to see the template functions definitions in order to produce object
code for the particular template arguments. It means that your template code
has to be in the include file. It also seems to mean that the #pragmas
interface and implementation won't behave properly in this case because it
introduces multiply defined simbols.
At least I can't find a way to make them work properly with the way I tried
to use them. What I do now is include the .h and .cc files in the modules
I need templates expanded and just include the .h file in those modules
where the template functions are refered to. I just don't put any #pragmas
in the .h and .cc files with template definitions.
Do all C++ compilers work this way? Will I get multiply defined simbols if
I try to compile my source files with a compiler that can 'link' templates?
Does it mean that no template librairies can exist? Does it mean that the
code will always get duplicated when templates are used?
Could there be a #define __LINKABLE_TEMPLATES that would permit us to develop
future-compilable code? At least with g++.
Wouldn't a #pragma expand_template "file.cc" be nice.
(see page 347 of the ARM)
Thanks for any answer.
--
Christian Dechamplain|
(819) 563-8951 |
dechc00@dmi.usherb.ca|
----------------------