help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can GCC guess where to find template definitions?


From: Dyre Tjeldvoll
Subject: Re: Can GCC guess where to find template definitions?
Date: Fri, 15 Apr 2005 09:15:44 +0200
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.2 (gnu/linux)

Tom Felker <tfelker2@uiuc.edu> writes:

> Hi all,
[snip]
>
> I know I could use some preprocessor hackery to make the .h include the
> .cpp file when necessary (my solution whenever I can), or just put
> everything in the header, or make a seperate .cpp file with explicit
> instantiations for everything I need, or use the #pragma interface thing
> (which I don't fully understand.)  But my goal is to get it to work
> without changing anything from the rather naive way it's done now.
>
> If a way to do this doesn't exist, would it be possible to add it as an
> option, or would that be too ugly to consider?  I'd give it a try if I
> thought it was plausible and if I could understand the code I'd be
> changing.

g++ may have something that can help you, but if your goal is to make a
portable program you can forget it :( The only standard way to do this
is by using the keyword export, and that is (to my knowledge) 
not suported by more than one (or a few) compiler vendors (e.g. EDG).

Without export you need the definition of the template available when
you instantiate it. Either put everything in the .h file or
create an .i(mp) file that gets included in the TUs where you
instantiate.

I don't know if gcc is planning to implement export, but it seems like
the current opinion is somewhat against export, even though it is in
the standard, because it is difficult to implement and doesn't really yield
all the benefits one would expect. Google for "export" in
comp.lang.c++.moderated or get a copy of the book "C++ Templates, The
Complete Guide" by Vandevoorde & Josuttis to know more about export.

>
> Have fun,

I'll try.

-- 
dt

However, experience shows that for many people and many applications a
dose of paranoia is reasonable - Bjarne Stroustrup


reply via email to

[Prev in Thread] Current Thread [Next in Thread]