I am trying to define a public static variable like this :
public :
static int j=0; //or any other value too
I am getting a compilation error on this very line : ISO C++ forbids in-class initialization of non-const static member `j’.
-
Why is it not allowed in C++ ?
-
Why are const members allowed to be initialized ?
-
Does this mean static variables in C++ are not initialized with 0 as in C?
Thanks !
From Bjarne Stroustrup’s C++ Style and Technique FAQ:
[dirkgently said it better]
As far as I know, as long as you declare the static member var in a .cpp it will be zero-initialized if you don’t specify otherwise: