aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2003-12-10 00:12:20 +0000
committerMax Horn2003-12-10 00:12:20 +0000
commit0f7f124de231b465e00a97b1f1a68a11ccafd7d5 (patch)
treeac8cfc9254a36caa4c2ef2a3b490048ce457cd3a /common
parentc67d2b5f553f776b449a9e1545daa31a227dbfc6 (diff)
downloadscummvm-rg350-0f7f124de231b465e00a97b1f1a68a11ccafd7d5.tar.gz
scummvm-rg350-0f7f124de231b465e00a97b1f1a68a11ccafd7d5.tar.bz2
scummvm-rg350-0f7f124de231b465e00a97b1f1a68a11ccafd7d5.zip
slightly altered singleton implemention, might help MSVC6, or might screw it even more :-)
svn-id: r11543
Diffstat (limited to 'common')
-rw-r--r--common/singleton.h18
1 files changed, 12 insertions, 6 deletions
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 T>
class Singleton
{
+private:
+ Singleton<T>(const Singleton<T>&);
+ Singleton<T>& operator= (const Singleton<T>&);
+
+ 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<T>() { }
~Singleton<T>() { }
-
-private:
- Singleton<T>(const Singleton<T>&);
- Singleton<T>& operator= (const Singleton<T>&);
};
+template <class T>
+T* Singleton<T>::_singleton=0;
+
} // End of namespace Common
#endif