Witam
próbuję dodać klasę Singleton do pliku DLL. Niestety dostaję informację o takim będzie:
error C2491: 'HE::Singleton<T>::~Singleton' : definition of dllimport function not allowed
error C2491: 'HE::Singleton<T>::destroySingleton' : definition of dllimport function not allowed
error C2491: 'HE::Singleton<T>::getSingletonPtr' : definition of dllimport function not allowed
error C2491: 'HE::Singleton<T>::Singleton' : definition of dllimport function not allowed
i nie mam pojęcia gdzie jest błąd. I przy okazji czy wykorzystywanie w programie singletonów to dobry pomysł?
#ifdef DLL_EXPORTS
#define DLL_API _declspec(dllexport)
#else
#define DLL_API _declspec(dllimport)
#endif
//Singleton.h
namespace HE
{
template<typename T>
class DLL_API Singleton
{
public:
Singleton();
virtual ~Singleton();
static T& getSingleton()
{
assert(mpInstance); return (*mpInstance);
}
static T* getSingletonPtr();
static void destroySingleton();
protected:
static T* mpInstance;
};
}
//Singleton.cpp
using namespace HE;
template<typename T> T* Singleton<T>::mpInstance = nullptr;
template<typename T>
T* Singleton<T>::getSingletonPtr()
{
return mpInstance;
}
...
export
w C++, albo jak rozwiązano eksportowanie typów generycznych z .DLLi pod .NET - w obu przypadkach mamy do czynienia z kodem pośrednim, z którego linker albo runtime generuje kod wynikowy...