Pleas have a look at this question. The OP wants to know why declaring variables globally didn't work in that case. In the sense, the OP tried it but it didn't work. If you look at the accepted answer for the question, it gives the solution by declaring those 2 variables as
static. That's correct and I've no problem with it. But it really does not explain anything related to why those 2 variables must be
static. On reading closely, we know that the OP tried global declaration, but since
static keyword was not used it didn't work. Therefore, the explanation regarding the usage of
static should have been there.
I know that the OP accepted the answer, so he/she is fine with it, even without the explanation of
static. But tomorrow, some other use comes with the same problem, will see the accepted answer, and goes back thinking just giving
static and putting it outside all the methods will do the trick, even without knowing, why
static was used in the first place.
My question is, what should be done in such a case? Just let it be as such, or, may be I should go and edit the answer(that would like a massive edit to the answer, since it has no explanation about
static to start with), or what else can be done in such a case?
P.S: I'm not asking this because the OP didn't accept my answer. I don't mind that at all. I just wanted the accepted answer to explain what the problem was, why it occurred and why the given code solved it. Also, it doesn't look good if I approach the OP saying, the answer you accepted is wrong. Accept mine. It would make the guy whose answer was accepted start hating me.
So any suggestions on what can be done?!