All pastes #949921 Raw Edit

Something

public text v1 · immutable
·published 2008-03-20 04:30 UTC
rendered paste body
// in .h
class MySingletonClass {
private:
    static MySingletonClass *instance;

    // private constructor
    MySingletonClass();

public:
    static MySingletonClass *Instance()
    {
        if (!instance)
            instance = new MySingletonClass();
        return instance;
    }

    void SomeMethod();
};

// in .cpp
MySingletonClass *MySingleClass::instance = NULL;

void SomeFunction()
{
    MySingletonClass::Instance()->SomeMethod();
}