Using static function variable vs class variable to store some state
问题 Lets say I have function like this: void processElement() { doSomething(someArray[lastProcessedElement + 1]); } The thing is, every time this function called, I need to the store the last element that I called doSomething on. So in here I have two choices: I can create a private class variable named lastProcessedElement and increment it's value every time that function is called. This approach seems most common. So the code can be something like this: class Foo { int lastProcessedElement = 0;