From: Jason Green 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: References: <38C03E09 DOT E7E7A8AC AT bluemartini DOT com> NNTP-Posting-Host: modem-116.flunitrazepam.dialup.pol.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 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