Hello,

Compiling with GCC

I am wondering why I have to declare the static value outside the class, even though I have declared it inside the class.

I understand that static members belong to the class and not the object created by the class. And private static members can only be accessed from static functions. However, it seems like I am declaring the s_nValue twice.

Can anyone explain why this is.

Many thanks,

Code:
class Something  
{  
 private:  
     static int s_nValue;  
 public:  
     static int GetValue() { return s_nValue; }  
 };  
   
int Something::s_nValue = 1; // initializer  
   
int main()  
{  
     std::cout << Something::GetValue() << std::endl;  
}