0

I have a helper class that needs a template definition and works fine locally.

Now I try to put it in a static libary and use it in another program.

But when I use it, the linker reports a non-existent symbol. Is it possible to export the template definition somehow?

core_global.h

#pragma once
#include <QtCore/qglobal.h>
#define CORE_EXPORT Q_DECL_EXPORT

helper.h

#pragma once
#include "core_global.h"

template <typename E>

class CORE_EXPORT Helper
{
public:

    Helper();
    E fromString(const QString& text);
    QString toString(E value);
};

helper.cpp

#include "Helper.h"
   
template<typename E>
Helper<E>::Helper()
{
}
       
template<typename E>
E Helper<E>::fromString(const QString& text)
{
    // do something
    return {};
}
       
template<typename E>
QString Helper<E>::toString(E value)
{
    //do something
    return {};
}
user2377283
  • 365
  • 1
  • 2
  • 12
  • Does this answer your question? [Why can templates only be implemented in the header file?](https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file) – G.M. Feb 14 '23 at 16:26

0 Answers0