mlimber wrote:
mlimber wrote:
See chapter 6 of _Modern C++ Design_ for more than you ever wanted to
know about templates in C++.
^^^^^^^^^
I meant "singletons" not "templates" (although, the latter might also
apply). --M
Thanks, I will try it out.
But this is the singleton template I was using, do you see any issues
why this would not start when the machine reboots.
class DLLEXPORT CSingleton
{
public:
// Return A reference to the instance of the CSingleton class.
// If there is no instance of the class yet, one will be created.
static T& Instance()
{
if (m_instance == 0 )
{
if (m_instance == 0)
{
m_instance = new T;
// exit processing function
std::atexit(CSingleton::DestroyInstance);
}
}
return *(CSingleton::m_instance);
};
// Destroys the CSingleton class instance.
// Be aware that all references to the single class instance will be
// invalid after this method has been executed!
static void DestroyInstance()
{
delete m_instance;
m_instance = NULL;
};
protected:
// shield the constructor and destructor to prevent outside sources
// from creating or destroying a CCSingleton instance.
inline explicit CSingleton() { CSingleton::m_instance =
static_cast<T*>(this); }
inline ~CSingleton() { CSingleton::m_instance = 0; }
private:
inline explicit CSingleton(CSingleton const&) {}
inline CSingleton& operator=(CSingleton const&) { return *this; }
private:
static T* m_instance; // CSingleton class instance
};
// static class member initialisation.
//template <typename T> T* CSingleton<T>::m_instance = 0;
~Enda
would give you any problems.