title: undefined reference to template function
body: <p>I have three files . The contents of main.cpp are</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;QString&gt;
  
  #include "util.h"
  
  int main()
  {
      using Util::convert2QString;
  
      using namespace std;
      int n =22;
      QString tmp = convert2QString&lt;int&gt;(n);
  
      return 0;
  }
  </code></pre>
  
  <p>util.h</p>
  
  <pre><code>namespace Util
  {
      template&lt;class T&gt;
      QString convert2QString(T type , int digits=0);
  }
  </code></pre>
  
  <p>util.cpp</p>
  
  <pre><code>namespace Util
  {
      template&lt;class T&gt;
          QString convert2QString(T type, int digits=0)
          {
              using std::string;
  
              string temp = (boost::format("%1%") % type).str();
  
              return QString::fromStdString(temp);
          }
  }
  </code></pre>
  
  <p>When I try to compile these files with following command I get undefined reference error</p>
  
  <pre><code>vickey@tb:~/work/trash/template$ g++ main.cpp  util.cpp -lQtGui -lQtCore  -I. -I/usr/local/Trolltech/Qt-4.8.0/include/QtCore -I/usr/local/Trolltech/Qt-4.8.0/include/QtGui -I/usr/local/Trolltech/Qt-4.8.0/include
  /tmp/cca9oU6Q.o: In function `main':
  main.cpp:(.text+0x22): undefined reference to `QString Util::convert2QString&lt;int&gt;(int, int)'
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>Is there something wrong with the template declaration or implementation ? why M I getting these linking errors :?</p>