delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/01/20/09:51:34

From: Jason Green <news AT jgreen4 DOT fsnet DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Library with templates - help !!!!!!!!!!!!!
Date: Sat, 20 Jan 2001 14:49:05 +0000
Organization: Customer of Energis Squared
Lines: 44
Message-ID: <ul8j6tofuvdpb22ms23d9ld99sr7hk3k25@4ax.com>
References: <94c3au$791$1 AT info DOT cyf-kr DOT edu DOT pl>
NNTP-Posting-Host: modem-45.elmiron.dialup.pol.co.uk
Mime-Version: 1.0
X-Trace: newsg1.svr.pol.co.uk 980002156 26905 62.136.92.45 (20 Jan 2001 14:49:16 GMT)
NNTP-Posting-Date: 20 Jan 2001 14:49:16 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

"Rafal Maj" <maj_rafal AT poczta DOT onet DOT pl> wrote:

> Hi,
> I have problem when I compile program using library with templates.
> Project file contains bugmain.cc & bug.cc. In this example, bugmain.cc is my
> mian program, bug.cc is my library & bug.h is library header. I have
> problems to build my program when I'm using templates in my library.
> I get error report :

> Error: bugmain.o: In function `main':
> bugmain.cc(2) Error: undefined reference to `box<int>::move(int)'

> I know, that there are options like -frepo, no-implict-templates, etc... but
> I realy don't know how to set them to make my exaple work.

You don't need to worry about those options for this particular
problem, it's not DJGPP specific.

> If You can help me, please write exacly what should be compiler & linker
> options, and what I have to change inside my source files.

ok, below is rearranged how it should be, note that bug.cc no longer
exists:

> ================== BUGMAIN.CC =================
> #include "bug.h"
int main() {     /* <-- main returns an int */
>   box<int> b;
>   b.move(5);
> }
> ================== BUG.H ===============
> template <class typ>
> class box {
>   public :
>     typ x,y;
>     void move(typ d);
> };

> template <class typ> void box<typ>::move(typ d) {
>   x+=d;  y+=d;
> }
> =========================================================

compile with: gpp -O2 -Wall -W bugmain.cc -o bugmain

- Raw text -


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