class MyClass { public: void method2() { static int i; ... } };
Will each instance of MyClass have the same i value, or will each instance have its own copy?
MyClass
i
static acts like in any regular function.
static
This means that i static inside MyClass::method2 , so there is only one instance.
MyClass::method2
Having one instance of a variable for each object is instance variables.
Each instance of MyClass will have one i value.