help-gplusplus
[Top][All Lists]
Advanced

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

Can GCC guess where to find template definitions?


From: Tom Felker
Subject: Can GCC guess where to find template definitions?
Date: Thu, 14 Apr 2005 19:44:24 -0500
User-agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.)

Hi all,

I'm in a programming class, and we have Sun's compilers available to us
remotely, but partly for convenience and partly for challenge, I'm trying
to develop on GCC at home.  My goal is to get the code we're given, which
compiles on Solaris, to compile without any changes on GCC.

The given code uses templates, declared in the .h file and defined in .cpp
files, and the client code just includes the .h.  So when the compiler
wants to instantiate the template, it doesn't have the declaration.

When Sun's compiler encounters this situation, it appears to guess that
templates declared in foo.h will be implemented in foo.cpp.  (When the
header and source file don't have the same basename, this breaks.)  Is
there any way to get GCC to do the same thing?

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.

Have fun,
-- 
Tom Felker, <tfelker2@uiuc.edu>
<http://vlevel.sourceforge.net> - Stop fiddling with the volume knob.

Life is like an analogy.



reply via email to

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