delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/03/04/15:07:56

From: Jason Green <news AT jgreen4 DOT fsnet DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: building source with C++ templates
Date: Sun, 05 Mar 2000 19:03:47 +0000
Organization: Customer of Planet Online
Lines: 43
Message-ID: <b795cskkebg0cmf9g14d7stjj8h87ikrii@4ax.com>
References: <38C03E09 DOT E7E7A8AC AT bluemartini DOT com>
NNTP-Posting-Host: modem-116.flunitrazepam.dialup.pol.co.uk
Mime-Version: 1.0
X-Trace: newsg2.svr.pol.co.uk 952197189 18354 62.136.95.244 (4 Mar 2000 19:13:09 GMT)
NNTP-Posting-Date: 4 Mar 2000 19:13:09 GMT
X-Complaints-To: abuse AT theplanet DOT net
X-Newsreader: Forte Agent 1.7/32.534
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Sergei Severin <sergei AT bluemartini DOT com> wrote:

> I am trying to figure out how to compile and link my program if I am
> using C++ templates. Here is the simple example of what I am trying to
> accomplish:
> 
> - I have 3 files

Only 2 files are required (as you have found).

> void main () {

main() returns int not void.

> - When I try to build it like:  gxx -o test.exe *.cpp   I get

You should normally enable warnings, and wildcards are a bad idea
IMHO.  This should compile main.cpp and produce test.exe, which I
think is your intention:

gxx -Wall main.cpp -o test

You could also use gpp if you have a recent version.

> I manage to build everything fine only in two cases: 1. if don't use
> templates at all or 2. If I use templates but keep declarations and
> implementations in one .h file

That is how templates work, the implementation has to be available to
the compiler when it compiles a file that uses the template class.

> In my project, the files are pretty large and I am required to separate
> class declarations from the implementation of member functions. So if
> anyone knows how to fix my problem, I would really appreciate your help
> with this.

I think most people tend to put the template declaration and
implementation together in the header.  If you need to split them then
you just have to arrange it so that the compiler sees them together
after your source has been through the pre-processor.

You could nest #include "test.cpp" in the file test.h, 
or you could #include both "test.cpp" and "test.h" in main.cpp

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019