Mail Archives: djgpp/1998/09/25/03:45:48
From: | Shue-Cheng CHEN <scchen AT ohriki DOT t DOT u-tokyo DOT ac DOT jp>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | A Problem with Template Class
|
Date: | 25 Sep 1998 07:09:18 GMT
|
Organization: | Graduate School of Engineering, The Univ. of Tokyo, Japan.
|
Lines: | 43
|
Message-ID: | <360B4190.1C2DD19F@ohriki.t.u-tokyo.ac.jp>
|
NNTP-Posting-Host: | chen.ohriki.t.u-tokyo.ac.jp
|
Mime-Version: | 1.0
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Hi!
I made a main program "test.cc" as follows,
#include <iostream.h>
#include "simarra.h" // Header for SimpleArray<class T>
int main()
{
SimpleArray<float> a;
for (int i=1; i<=6; i++) {
a[i] = i * 1.1;
cout << a[i] << " ";
}
cout << endl;
return 0;
}
It's strange that this main program only works when I placed all
implementations of the class SimpleArray<T> in the same test.cc.
When the implementations of the main program and the class were
separated in two different files, e.g., test.cc and SimArra.cc,
in the linking stage, I always got the messages
1.o: In function `main':
1.cc:1: undefined reference to `SimpleArray<float>::SimpleArray(void)'
1.cc:2: undefined reference to `SimpleArray<float>::SimpleArray(void)'
1.cc:6: undefined reference to `SimpleArray<float>::operator[](int)'
1.cc:7: undefined reference to `SimpleArray<float>::operator[](int)'
1.cc:11: undefined reference to `SimpleArray<float>::~SimpleArray(void)'
1.cc(.text+0xc9): undefined reference to
`SimpleArray<float>::~SimpleArray(void)'
1.cc(.text+0xf3): undefined reference to
`SimpleArray<float>::~SimpleArray(void)'
1.cc(.text+0x113): undefined reference to
`SimpleArray<float>::~SimpleArray(void)'
Why did it become undefined?
Thank you in advance.
Shue-Cheng Chen
- Raw text -