Singleton

Template class for singleton pattern.  Is non-copyable to enforce correct behavior.

Defining a Singleton

class YourClass : public Singleton<Class>
{
// class definition
};

Using The Singleton

new YourClass;
YourClass& yc(YourClass::getInstance());

// use yc

YourClass::destroy();
Summary
Template class for singleton pattern.
Initialize the instance of the singleton, can be done explicitly if order of construction matters.
Destroy the instance of the singleton, can be done explicitly if order of destruction matters.
Get a reference to the instance of the derived class.

initialize

static void initialize()

Initialize the instance of the singleton, can be done explicitly if order of construction matters.  Will be done on first call to getInstance otherwise.

destroy

static void destroy()

Destroy the instance of the singleton, can be done explicitly if order of destruction matters.  Will be done automatically if not done.

getInstance

static T& getInstance()

Get a reference to the instance of the derived class.

static void initialize()
Initialize the instance of the singleton, can be done explicitly if order of construction matters.
static void destroy()
Destroy the instance of the singleton, can be done explicitly if order of destruction matters.
static T& getInstance()
Get a reference to the instance of the derived class.