public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: missing function
@ 2003-11-23 22:06 Dara Hazeghi
  0 siblings, 0 replies; 2+ messages in thread
From: Dara Hazeghi @ 2003-11-23 22:06 UTC (permalink / raw)
  To: codaditasso; +Cc: gcc-help

Hello,

template definitions must be present to their callers,
ie when gcc finishes preprocessing prova91.cpp, it
must see the contents of prova92.cpp (where you define
prova).

The conventional method of doing this is a bit weird,
but something like this:
change prova92.h to read:

#ifndef _prova92_h
#define _prova92_h
template <class T> void prova(T k);

#include "prova92.cpp"
#endif

To compile, you just compile prova91.cpp, and
everything gets pulled in as needed.

Hope that helps,

Dara

__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* missing function
@ 2003-11-23 15:22 codaditasso
  0 siblings, 0 replies; 2+ messages in thread
From: codaditasso @ 2003-11-23 15:22 UTC (permalink / raw)
  To: gcc-help

Hello
I have write the following files:

prova91.cpp:

1 #include "prova92.h"
2
3 int
4 main(){
5      int k=1;
6      prova(k);
7      return 0;
8 };

prova92.h:

1 template <class T> void prova(T k);

prova92.cpp:

1 #include <iostream>
2 #include "prova92.h"
3 using namespace std;
4 template <class T> void
5 prova(T k){
6           cout<<k<<"\n";
7 };

 And the i have digit the following command to compile the program:

bash-2.05b# g++ -c prova91.cpp
bash-2.05b# g++ -c prova92.cpp
bash-2.05b# g++ -o prova9 prova91.o prova92.o

But i have obtained the following error from the last command:

prova91.o(.text+0x1e): In function `main':
: undefined reference to `void prova<int>(int)'
collect2: ld returned 1 exit status

What's the problem ? Maybe the template function and class must be written
only in the header files?

Greetings from Pinzi

__________________________________________________________________
Tiscali ADSL SENZA CANONE, paghi solo quando navighi!
E in più il modem e' GRATIS! Abbonati subito.
http://point.tiscali.it/adsl/index.shtml



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-11-23 22:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-23 22:06 missing function Dara Hazeghi
  -- strict thread matches above, loose matches on Subject: below --
2003-11-23 15:22 codaditasso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).