In using the following Singleton implementation:
01 class Singleton
02 {
03 public:
04 static Singleton* Instance();
05
06 protected:
07 Singleton();
08 Singleton(const Singleton&);
09 Singleton& operator= (const Singleton&);
10 };
11
12 Singleton* Singleton::Instance()
13 {
14 static Singleton m_instance;
15 return &m_instance;
16 }
My question pertains to line 14.
Static methods normally operates on static variables, thus it is clear that the Instance() method operates on the static m_instance variable. But it seems that removing "static" from line 14 produces exactly the same result, i.e. only one instance is ever created.
Is it correct to assume that any variable declared inside a static method is automatically set as static?