-3

code is

struct {
  protected:
   static int labelCounter;
};
peterchen
  • 40,917
  • 20
  • 104
  • 186
Gangesh
  • 813
  • 1
  • 7
  • 10
  • how would you assign the value of a protected non static member? there some difference in initialization compared to an instance method, but no (not much) difference in value assignment – Gian Paolo Feb 17 '17 at 09:25
  • I dont see what is unclear about this thread... How to initialize a static member. http://stackoverflow.com/questions/19469475/struct-static-member-meaning-definition – J3STER Feb 17 '17 at 09:54

1 Answers1

2

protected members can be assigned in methods that belong to the class, or any derived class.

Your static member can be initialized normally, but you have to give a name to the struct:

struct MyStruct { protected: static int labelCounter; };

// .cpp:
int MyStruct::labelCounter = 12;
peterchen
  • 40,917
  • 20
  • 104
  • 186