M
Michael Schutte
I am trying to write a wrapper class, which can store any data type to
wrap it into a class. My compiler is gcc (for c++) version 3.3.1 on a
SuSE Linux 9.0 system.
I start with the following code:
template <typename T>
class Wrapper {
public:
Wrapper(T avalue);
private:
int value;
};
in the header wrapper.h, and in wrapper.cpp:
#include "wrapper.h"
template <typename T>
Wrapper<T>::Wrapper(T avalue) {
value = avalue;
}
When I compile now, using
$ gcc -c wrapper.cpp
gcc doesn't report any errors.
Linking with the resulting wrapper.o:
$ gcc -o testwrapper testwrapper.cpp wrapper.o
/tmp/abcdefgh.o(...): In function `main':
undefined reference to Wrapper<int>::Wrapper[in-charge](T)
collect2: ld returned 1 status
What have I done wrong?
wrap it into a class. My compiler is gcc (for c++) version 3.3.1 on a
SuSE Linux 9.0 system.
I start with the following code:
template <typename T>
class Wrapper {
public:
Wrapper(T avalue);
private:
int value;
};
in the header wrapper.h, and in wrapper.cpp:
#include "wrapper.h"
template <typename T>
Wrapper<T>::Wrapper(T avalue) {
value = avalue;
}
When I compile now, using
$ gcc -c wrapper.cpp
gcc doesn't report any errors.
Linking with the resulting wrapper.o:
$ gcc -o testwrapper testwrapper.cpp wrapper.o
/tmp/abcdefgh.o(...): In function `main':
undefined reference to Wrapper<int>::Wrapper[in-charge](T)
collect2: ld returned 1 status
What have I done wrong?