Are static vars in a method body shared by all instances

c++

Solution

`static`, here, operates as in any regular function.

Which means that `i` is `static` within `MyClass::method2`, so there is one and only one instance of it.

Having one instance of a variable per object is what instance variables are for.

Problem

``` class MyClass { public: void method2() { static int i; ... } }; ``` Will every instance of `MyClass` share one value `i`, or will each instance have its own copy?

Original source