Hi,
This singleton code doesn't work :
//////////////////////////////////////////////////// code /////////////:
#ifndef __SINGLETON
#define __SINGLETON
#include <stddef.h>
template<typename T>
class Singleton
{
protected:
Singleton() {}
~Singleton() { _singleton = NULL;}
public:
static T inline *getInstance()
{
if ((static_cast<T*>(NULL)) == _singleton) { _singleton = new T; }
return (static_cast<T*>(_singleton));
}
static void kill()
{
if (NULL != _singleton)
{
delete _singleton;
_singleton = NULL;
}
}
private:
static T *_singleton;
};
template<typename T>
T *Singleton<T>::_singleton = (static_cast<T*>(NULL));
#endif
/////////////////////////// end of code //////////////////////////////////////////////
In my case, "_singleton" variable is always null, even after instantiation.
Is this a compiler/linker problem?
Must I use special options ?
Note : Templates without static variables are working on the same environment.
Thanks by advance.
Gilles Peltier