I have 2 singleton classes as following, any body can tell me what's the difference????
class Singleton {
public:
static Singleton& Instance()
{
static Singleton m_inst;
return m_inst;
}
private:
Singleton ();
~Singleton ();
}
class Singleton {
public:
static Singleton& Instance()
{
return m_inst;
}
private:
Singleton ();
~Singleton ();
static Singleton m_inst;
}
In first class, the local static variable is declared inside the function; in second one, it is declared inside the class.
class Singleton {
public:
static Singleton& Instance()
{
static Singleton m_inst;
return m_inst;
}
private:
Singleton ();
~Singleton ();
}
class Singleton {
public:
static Singleton& Instance()
{
return m_inst;
}
private:
Singleton ();
~Singleton ();
static Singleton m_inst;
}
In first class, the local static variable is declared inside the function; in second one, it is declared inside the class.