delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/09/07/22:46:04

From: Endlisnis <s257m AT unb DOT ca>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: help - template<class T>
Date: Mon, 07 Sep 1998 19:07:42 -0300
Organization: NBTel Internet
Lines: 30
Message-ID: <35F4592E.F6BBC812@unb.ca>
References: <35f10110 DOT 1073722 AT news DOT telepac DOT pt> <35F14F9C DOT 8570B044 AT unb DOT ca> <35F3C579 DOT 4E8D7755 AT asim DOT lip6 DOT fr>
NNTP-Posting-Host: fctnts05c61.nbnet.nb.ca
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Fabrice ILPONSE wrote:
> >         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.
> 
>         I'm not sure!!
>         You have to put all the class in the header.
>         The functions are  recreated each time you declare a new template
> variable of an inexisting type.
> 
>         eg.
>                 matrix <int> a,b;
>                 matrix <float> c;
> 
>         in fact there'll be 2 differents classes: 1 for int and 1 for float.
>         So as the compiler need to know the body of the functions to rebuild
> them, they must be in the header file.
	And this happens at COMPILE time, not LINK time.  If during COMPILE time,
there are no instances, then you can't link a program with instances. 
Conclusion:  Don't make a template library file.  You can't precompile
templates, they must be compiled in the same module as the declarations.
-- 
     (\/) 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