-
Global vs Class
A newbie here (about 4 months now of off-on hobby programming)... but I'm having trouble understanding Class in C++... I have a couple of programs whereby I set up a "global array" and they work well... but I'm reading that maybe my global arrays should be in a class.
Could someone explain in English why?
Thanks!
-
A class is just a way to organize data and various operations (methods) that can do different things on that data. For example, the std::string class contains the string data itself plus a handful of methods to modify, retrieve, chop, etc. the string.
Classes are very useful for larger programs where organizing data is critical. In your case, it might be helpful to organize your array into a class with associated methods, especially if you want to reuse the class in another program or if you want to have more than one copy of the array in a program.