This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
problems with g++ templates
- From: Bernhard Rückerl <bernhard_rueckerl at freenet dot de>
- To: gcc-help at gcc dot gnu dot org
- Date: Sat, 30 Oct 2004 17:38:58 +0200
- Subject: problems with g++ templates
- Reply-to: bernhard_rueckerl at freenet dot de
Hello,
I have troubles with using class templates with g++ version 3.3.1
I have a file testt.h:
template<typename T>
class TestT
{
private:
T x;
public:
void setvalue( const T & px);
T getvalue( );
};
and the according file testt.cpp:
#include "testt.h"
template<typename T>
void TestT<T>::setvalue(const T & px)
{
x = px;
}
template<typename T>
T TestT<T>::getvalue( )
{
return x;
}
And a file testmain.cpp with a main using this template class:
#include "testt.h"
#include <iostream>
main()
{
TestT<double> w;
w.setvalue( 2.0 );
cout << w.getvalue( );
}
b
When I try to compile an link the programm with
g++ -o testmain -g testmain.cpp testt.cpp
I get the error message:
/tmp/cclxyVIZ.o(.text+0x2c): In function `main':
/home/bernhard/programme/test/testmain.cpp:8: undefined reference to
`TestT<double>::setvalue(double const&)'
/tmp/cclxyVIZ.o(.text+0x3e):/home/bernhard/programme/test/testmain.cpp:9:
undefined reference to `TestT<double>::getvalue()'
I also tried the options of g++ which seem relate to templates but I
always get these errors or the options are deprecated.
As I know my c++-code is correct. What can be the reason?
yours sincerely and thanks in advance
Bernhard Rückerl