In general, you should try to make your variables and functions as local as they possibly can be. Only make them visible to the parts of the program that need to see them. It is also a good practice to avoid the use of global variables. Your code will be more portable, easier to maintain and debug, and less likely to interfere with code from other libraries. It turns out that both data and function members of a class can be made static .
Static members behave like ordinary members in many ways.
They are contained within the scope of the class, and do not cloud the global namespace or names used in other classes. It is not even necessary that an object of the class to be constructed to access the static members. Static Class Data Members Static data members are shared by all object instances of that class. Each class instance sees and has access to the same static data. The static data is not part of the class object but is made available by the compiler whenever an object of that class comes into scope.