Skip to content
Gautier Lefebvre edited this page Feb 13, 2018 · 3 revisions

Singleton

There is a Singleton templated class easily usable within the framework.

Creating a singleton class

class Foo :public fwk::Singleton<Foo> {
    friend class fwk::Singleton<Foo>;

    // delete every default constructors
    Foo(const Foo&) = delete;
    Foo(const Foo&&) = delete;
    Foo& operator=(const Foo&) = delete;

    // keep empty ctor and dtor private
    Foo(void);
    virtual ~Foo(void);
};

Using the singleton class

You can get the singleton class instance by doing this:

Foo& foo = Foo::get();
Foo* bar = Foo::asPtr();

You can delete the singleton class instance by doing this:

Foo::destroy();
Clone this wiki locally