Static member variables are not part of any one struct variable. All the struct variables will use the same static variable. Therefore, the static variable has to be created outside the struct:
-
Class A
-
{
-
-
struct start
-
{
-
static int var;
-
};
-
-
};
-
-
//in a .cpp ffile
-
-
int A::start::var;
-
Please note that in C++ class and struct are interchangeable. That is, if your members are declared as public/private/protected, there is no difference between a class and a struct. The single difference is when you do not specify public/private/protected, the default access for a class is private whereas the default access for a struct is public. Underneath it all, classes are implemented as structs.