problems with g++ templates

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux