From: Manni Heumann Newsgroups: comp.os.msdos.djgpp Subject: Re: Templates Date: 9 Jul 2001 17:15:33 GMT Lines: 33 Message-ID: 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 cTest { public : void fun(); }; > ---test.cc--- > template void cTest::fun() { } > And this is ok, I can use it : > ---main.cc--- > #include "test.h" > int main() { cTest t; t.fun(); return 0; } > > This generates error at link-time, that linker can't find > body of void cTest::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 " 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