title: Understanding template classes in c++ - problem with new-operator
body: <p>Dear all, I've been stuck with this problem now for a few days and my searches were not successful.</p>
  
  <p>What I am trying to do:
  I want a template reader class (VariableReader) to handle different types of variables (usually unsigned int and pointers to vector).</p>
  
  <p>I started with </p>
  
  <pre><code>#ifndef READER_H_
  #define READER_H_
  #include &lt;string&gt;
  
  namespace BAT {
  template &lt;typename variableType = unsigned int&gt;
  class VariableReader {
  public:
   VariableReader&lt;variableType&gt;();
   VariableReader&lt;variableType&gt;(std::string varName);
   virtual ~VariableReader&lt;variableType&gt;();
   std::string getVariableName();
   void setVariableName(std::string varName);
   bool isValidVariableName(std::string varName);
   variableType getVariable();
  private:
   std::string variableName;
   variableType variable;
  
  };
  
  }
  
  #endif
  </code></pre>
  
  <p>and</p>
  
  <pre><code>#include "../../interface/Readers/VariableReader.h"
  
  namespace BAT {
  
  template&lt;typename variableType&gt;
  VariableReader&lt;variableType&gt;::VariableReader() :
   variableName("") {
   // TODO Auto-generated constructor stub
  }
  
  template &lt;typename variableType&gt;
  VariableReader&lt;variableType&gt;::VariableReader(std::string varName) :
   variableName(varName) {
  
  }
  
  template &lt;typename variableType&gt;
  std::string VariableReader&lt;variableType&gt;::getVariableName() {
   return variableName;
  }
  
  template &lt;typename variableType&gt;
  void VariableReader&lt;variableType&gt;::setVariableName(std::string varName) {
   if (VariableReader::isValidVariableName(varName)) {
    variableName = varName;
   }
  }
  
  template &lt;typename variableType&gt;
  bool VariableReader&lt;variableType&gt;::isValidVariableName(std::string varName) {
   return varName != "";
  }
  
  template &lt;typename variableType&gt;
  VariableReader&lt;variableType&gt;::~VariableReader() {
   // TODO Auto-generated destructor stub
  }
  
  }
  </code></pre>
  
  <p>However, although it seems to compile I can't use it within other projects. 
  EDIT: forgot to post test-code:</p>
  
  <pre><code>#include "cute.h"
  #include "ide_listener.h"
  #include "cute_runner.h"
  
  #include "Readers/VariableReader.h"
  using namespace BAT;
  
  static VariableReader&lt;int&gt; *reader;
  
  void setUp(){
  reader = new VariableReader&lt;int&gt;::VariableReader();//this is problem-line
  }
  
  void thisIsATest() {
      ASSERTM("start writing tests", false);  
  }
  
  void runSuite(){
      cute::suite s;
      //TODO add your test here
      s.push_back(CUTE(thisIsATest));
      cute::ide_listener lis;
      cute::makeRunner(lis)(s, "The Suite");
  }
  
  int main(){
      runSuite();
  }
  </code></pre>
  
  <p>I get following error message:</p>
  
  <pre><code>Building target: BAT_Tests
  Invoking: GCC C++ Linker
  g++ -L"/workspace/BAT/Debug Gcov" -fprofile-arcs -ftest-coverage -std=c99 -o"BAT_Tests"  ./src/Test.o   -lBAT
  ./src/Test.o: In function `setUp()':
  /workspace/BAT_Tests/Debug Gcov/../src/Test.cpp:13: undefined reference to `BAT::VariableReader&lt;int&gt;::VariableReader()'
  collect2: ld returned 1 exit status
  make: *** [BAT_Tests] Error 1
  </code></pre>
  
  <p>As I understand it the linker tries to find the constructor for VariableReader, which is not explicitly defined since I want to have a general constructor only.</p>
  
  <p>Please help me to understand what I am missing.</p>