From 0f7f124de231b465e00a97b1f1a68a11ccafd7d5 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 10 Dec 2003 00:12:20 +0000 Subject: slightly altered singleton implemention, might help MSVC6, or might screw it even more :-) svn-id: r11543 --- common/singleton.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'common') diff --git a/common/singleton.h b/common/singleton.h index 89d912f69a..665ef3d72e 100644 --- a/common/singleton.h +++ b/common/singleton.h @@ -31,6 +31,12 @@ namespace Common { template class Singleton { +private: + Singleton(const Singleton&); + Singleton& operator= (const Singleton&); + + static T* _singleton; + public: static T& instance() { // TODO: We aren't thread safe. For now we ignore it since the @@ -40,18 +46,18 @@ public: // semi-random. If we use multiple singletons, the destruction // order might become an issue. There are various approaches // to solve that problem, but for now this is sufficient - static T singleton; - return singleton; + if (!_singleton) + _singleton = new T; + return *_singleton; } protected: Singleton() { } ~Singleton() { } - -private: - Singleton(const Singleton&); - Singleton& operator= (const Singleton&); }; +template +T* Singleton::_singleton=0; + } // End of namespace Common #endif -- cgit v1.2.3