delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/07/09/13:30:49

From: Manni Heumann <manni DOT heumann AT gmx DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Templates
Date: 9 Jul 2001 17:15:33 GMT
Lines: 33
Message-ID: <Xns90D9C44F98AEDmanniheumanngmxde@130.133.1.4>
References: <9iarst$mm5$1 AT info DOT cyf-kr DOT edu DOT pl>
NNTP-Posting-Host: 129.70.164.224
X-Trace: fu-berlin.de 994698933 18837834 129.70.164.224 (16 1428 [54749])
User-Agent: Xnews/4.06.22
X-Face: "c)Go+A65AgR*9'!B)BMLM$kYg6HDG!_g'DAsj*ALo%=kp{X&abs&t\G0F~*r?VRj#|4=6)M.RJPnD]Ql:B<-7A^EAYFpDpZRMoJy?80^3B3b AT DXb%MTyOD.*4wu&Xt6o*+6`r5E
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Rafal Maj (Raf256) wrote in message
news:9iarst$mm5$1 AT info DOT cyf-kr DOT edu DOT pl: 

> Hi,
[snip]

> ---test.h---
> template <class typ> class cTest { public : void fun(); };
> ---test.cc---
> template <clas typ> void cTest<typ>::fun() {  }
> And this is ok, I can use it :
> ---main.cc---
> #include "test.h"
> int main() { cTest<int> t; t.fun(); return 0; }
> 
> This generates error at link-time, that linker can't find
> body of void cTest<int>::fun()...

There are two problems here. 
The first is with your code. You have to export "fun" to make it 
accessible in other translation units (e.g. in  main.cc). So you 
could insert "export " before "template <class typ>" in test.cc.
The second problem is with the compiler: gcc doesn't support the 
use of export. It will ignore the attempt and compile the 
program exactly as you posted it.
Sounds like a catch-22? It is. You will have to take the 
definition from test.cc and put it into test.h, so that it is 
known in main.cc and the other source files.

HTH,

Manni

- Raw text -


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