This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: One-definition rule for inline functions


On 8 March 2012 01:44, Timothy Madden wrote:
>
> What does g++ do with this template ?
> Does it really compile any templates in each and every .cc file that they
> are used in ?

Yes, as it says at the same page
(http://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html) templates also
have vague linkage. If you follow the "Where's the template?" link
there's a whole page on the topic:
http://gcc.gnu.org/onlinedocs/gcc/Template-Instantiation.html (ignore
the paragraph about "a future version of G++")

You can use an explicit instantiation declaration (i.e. "extern
template") to suppress the implicit instantiation in every file that
uses the template:

extern template void draw_unit_vector<int>();

If you do that then you must ensure that an explicit instantiation
definition appears in exactly one object file:

template void draw_unit_vector<int>();


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]