www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/01/22/05:51:51

From: "Sebastian Moleski \(SurakWare\)" <smoleski AT surakware DOT com>
Newsgroups: comp.lang.c++,comp.os.msdos.djgpp
Subject: Re: Authors of DJGPP / GCC - #export needed !
Date: Mon, 22 Jan 2001 10:54:20 +0100
Organization: T-Online
Lines: 33
Message-ID: <94h011$s6u$00$1@news.t-online.com>
References: <94ejfb$5a5$1 AT info DOT cyf-kr DOT edu DOT pl> <94feh0$8k6$1 AT SOLAIR2 DOT EUnet DOT yu> <94g97o$3dp$1 AT info DOT cyf-kr DOT edu DOT pl>
Mime-Version: 1.0
X-Trace: news.t-online.com 980157281 00 28894 FhIoebXS9AWlz 010122 09:54:41
X-Complaints-To: abuse AT t-online DOT com
X-Sender: 520006341874-0001 AT t-dialin DOT net
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2919.6700
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Rafal Maj" <maj_rafal AT poczta DOT onet DOT pl> schrieb im Newsbeitrag
news:94g97o$3dp$1 AT info DOT cyf-kr DOT edu DOT pl...
> I think that this doesn't work...  I want to have template class
declaration
> in lib.h, it's definition in lib.cc and I want to use this class in
main.cc
> with includes lib.h...
> I write it like this :
> lib.h :        #pragma interface "lib.h"    template <class typ> class
cBox
> { public : void move(); };
> lib.cc :      #pragma implementation "lib.h"    template <class typ> void
> cBox<typ>::move() { /* ...................... */ };
> main.cc : #include "lib.h"   main() { cBox<int> obj;  obj.move();  }
> My project file :  lib.cc  main.cc
> I used -f-external-templates.
> But still I get the same error, like  : undefined reference to
> Box():move()  - linker doesnt see definition of cBox<>::move( ) in lib.cc
>
> Can You PLEASE correct this litle example ? I turned
> on -f-external-templates option in Oprions/Compiler/CXX flags - is it
> correct ?

You just can't do this.

For the compiler to be able to make calls to templatized functions, it needs
to see either (a) the full definition or (b) every instantiation of the
template must be done explicitely. You can't separate the declaration from
the definition like you can usually do with external functions or classes.

sm


- Raw text -


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