delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/09/05/11:16:22

From: Endlisnis <s257m AT unb DOT ca>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: help - template<class T>
Date: Sat, 05 Sep 1998 11:50:04 -0300
Organization: NBTel Internet
Lines: 32
Message-ID: <35F14F9C.8570B044@unb.ca>
References: <35f10110 DOT 1073722 AT news DOT telepac DOT pt>
NNTP-Posting-Host: fctnts10c54.nbnet.nb.ca
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Jorge Bruno S. S. Morgado wrote:
> template<class T>
> class matrix
> {
> gxx -c -o math.o math.cc
> gxx -c -o main.o main.cc
> gxx -o test.exe main.o math.o
> 
> but this simply doesent work, it gives me lots of errors like:
> function <double> determinant(void) in class matrix not defined, and
> things like that.
> I've also noticed that the file math.o is very smal (only 375 bytes),
> and that, if I put the all class in the file math.h, and just include
> it from main.cc, it all goes fine, but this way, every time I make a
> change in another included file, I have to recompile all of it again.
> 
> Also, when I do something like this (using varios pre-compiled files)
> with C (not C++) it works just fine.
> 
> Is this a bug with gxx ?
> Why does this happens ?
	I think it has to do with the way templates are handled.  math.o is small
because there is (effectively) nothing in it.  Templates are only compiled
when a reference to them if found.  No references are found in math.cc.  I
don't think the linker will link templated functions that had no instances
during compilation.
-- 
     (\/) Endlisnis (\/)
          s257m AT unb DOT ca
          Endlisnis AT GeoCities DOT com
          Endlis AT nbnet DOT nb DOT ca

- Raw text -


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