I have a question related to the static class member in C++. Based on my understanding of C++, the static class number is supposed to exist before the class's instance is created. It is possible to initialize the const static member variable, but for the non-const static member we cannot initialize it within the class. Therefore, my question is where we should initialize the non-const static class. It seems to me that the only stage for the non-const static class is before the main program is run as the following codes illustrate:
using namespace std;
class C
{
public:
static int Value;
};
int C::Value = 2;
int main()
{
// int C::Value = 2; //ERROR!
cout<<C::Value<<endl;
return 0;
}
Are there other ways to initialize it? Thanks!
using namespace std:
with a colon? Is this actual code?