I have the following class
class Singleton
{
private:
static Singleton *p_inst;
Singleton();
public:
static Singleton * instance()
I will be brief: it depends on your compiler.
Now, you have to realize that you may not need this.
There are 2 ways to deal with this, that do not require any multithread awareness.
static
instance instead of dynamically allocate it. Safe and simple. May cause issue with initialization order if you need to access it from another static
variablemain
.Of course, the real question is: can't you just pass a reference to the object rather than creating a global variable ? It would make testing easier ;)