A singleton is perhaps the simplest design pattern, common to many programming languages and it’s the way to allow one and only one instance of a class. More...
#include <common.h>
Static Public Member Functions | |
static T & | instance () |
Protected Member Functions | |
Singleton () | |
virtual | ~Singleton () |
Private Member Functions | |
Singleton (const Singleton &) | |
Singleton & | operator= (const Singleton &) |
T & | operator= (const T &) |
A singleton is perhaps the simplest design pattern, common to many programming languages and it’s the way to allow one and only one instance of a class.
The key to creating a singleton is to prevent the client programmer from having any control over the lifetime of the object. To do this, all constructors are declared private, so that we also prevent the compiler from implicitly generating any constructors. Also the copy constructor and assignment operator (which intentionally have no implementations, as they will never be called) are declared private to prevent any sort of copies being made.
static T& Singleton< T >::instance | ( | ) | [inline, static] |
T& Singleton< T >::operator= | ( | const T & | ) | [private] |