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?
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?
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.