Linker probs with template classes
Werner Modenbach
modenbach at alc.de
Fri Jan 7 18:36:08 GMT 2000
Hi there!
Maybe there is someone who can give me a hint on my problem (I spent allready
days on it :-(( )
I have a sinple template class for a circular array and I reduced it to a
minimum:
-----------------------------------------------
circularArray.h:
template <class T>
class circularArray {
public:
circularArray(int size) : arraySize(size){};
~circularArray(){};
protected:
T* Elements;
int arraySize;
};
-----------------------------------------------
main.cpp:
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <iostream.h>
#include <stdlib.h>
#include <circularArray.h>
int main(int argc, char** argv){
circularArray<int> a(10);
cout << "Hello, World!" << endl;
return EXIT_SUCCESS;
}
-----------------------------------------------
The program works fine so far.
If i change the definition of the constructor to:
-----------------------------------------------
in circularArray.h:
circularArray(int size);
-----------------------------------------------
Create circularArray.cpp:
#include <circularArray.h>
template <class T>
circularArray<T>::circularArray(int size){
arraySize = size;
}
The following messages apear in the log window:
c++ -DHAVE_CONFIG_H -I. -I. -I.. -O0 -g3 -Wall -c circularArray.cpp
c++ -DHAVE_CONFIG_H -I. -I. -I.. -O0 -g3 -Wall -c main.cpp
c++ -O0 -g3 -Wall -o circular_test circularArray.o main.o
main.o: In function `circularArray<int>::~circularArray(void)':
/home/werner/circular_test/circular_test/circularArray.h:17: undefined reference
to `circularArray<int>::circularArray(int)' gmake: *** [circular_test] Error 1
*** Fehler ***
circularArray.h:17 is the line where the destructor is defined;
~circularArray(){};
If I define more methods of the class everything is fine as far as I define
everything in the headerfile.
Sorry for the OT question! I really have no idea.
- Werner -
--
---------------------------------------
Werner Modenbach modenbach at alc.de
ALC Computertechnik GmbH http://www.alc.de
More information about the KDevelop
mailing list