www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/06/10/21:16:29

From: Jason Green <news AT jgreen4 DOT fsnet DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: template problem in djgpp
Date: Sun, 10 Jun 2001 23:41:39 +0100
Lines: 40
Message-ID: <cis7ito5vn75j0mtk2tko71d00sou8iu8b@4ax.com>
References: <9fvfgf$obj$1 AT news DOT lth DOT se>
NNTP-Posting-Host: modem-55.fermium.dialup.pol.co.uk
Mime-Version: 1.0
X-Trace: newsg2.svr.pol.co.uk 992212898 31986 62.136.69.183 (10 Jun 2001 22:41:38 GMT)
NNTP-Posting-Date: 10 Jun 2001 22:41:38 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

"Tomas Nilsson" <tnidt97 AT student DOT vxu DOT se> wrote:

> Hello,
> I have a problem with templates i djgpp 2.03. I have tried the following
> program:

Put the class declaration *and* implementation in the header:

> file class1.h:
> template<class TYPE>
> class class1 {
> private:
>         TYPE T;
> public:
>         void f1();
> };

> template <class TYPE> void class1<TYPE>::f1() {}
> 
> file main.cpp
> #include"class1.h"
> int main() {
>         class1<int> c1;
>         c1.f1();
> }
> 
> The program compiles without errors and warnings, but then something goes
> wrong in the
> linking process. The linker ld in djgpp returns the error message "undefined
> reference to class<int>::f1(void)". This is very strange, because the UNIX
> compiler CC can compile and build this program without any problem, and CC
> one of the best approximation of the C++ standard I know.
>     Can anyone see what could be causing this problem

gcc needs to see the class definition at compile time, otherwise
class1<int> does not exist at link time.

> and why it works in CC and not djgpp?

gcc DTRT here, so strictly speaking the other CC is buggy.

- Raw text -


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