Friday, 1 September 2017

c++ - undefined reference to template function

The implementation of a non-specialized template must be visible to a translation unit that uses it.



The compiler must be able to see the implementation in order to generate code for all specializations in your code.



This can be achieved in two ways:



1) Move the implementation inside the header.



2) If you want to keep it separate, move it into a different header which you include in your original header:




util.h



namespace Util
{
template
QString convert2QString(T type , int digits=0);
}
#include "util_impl.h"



util_impl.h



namespace Util
{
template
QString convert2QString(T type, int digits=0)
{
using std::string;


string temp = (boost::format("%1") % type).str();

return QString::fromStdString(temp);
}
}

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...