What are static variables designed for? What's the difference between static int and int?
See Question&Answers more detail:osWhat are static variables designed for? What's the difference between static int and int?
See Question&Answers more detail:osThe static
keyword has four separate uses, only two of which are closely related:
Both static data members and static local variables can become hidden global state, and should be used carefully.
Now which two are closely related? It's not the two class members—the warning about global state gives it away. You can consider static data members as static local variables, where the functions to which they belong are all methods of the class, instead of a single function.
I found many related questions, but, surprisingly, no duplicates.