Thread: Global vs Class

  1. #1
    Registered User
    Join Date
    Aug 2022

    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?

  2. #2
    Registered User
    Join Date
    May 2012
    Arizona, USA
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global class object?
    By AvidGamer in forum C++ Programming
    Replies: 14
    Last Post: 09-13-2010, 06:41 AM
  2. Global Access to Global Class without so many pointers
    By parad0x13 in forum C++ Programming
    Replies: 1
    Last Post: 11-11-2009, 02:48 PM
  3. global class pointers
    By dpro in forum Windows Programming
    Replies: 10
    Last Post: 11-17-2004, 06:24 PM
  4. defining and using a global class
    By cjschw in forum C++ Programming
    Replies: 4
    Last Post: 03-05-2004, 09:51 PM
  5. no... wtf!!!?? ( Global class is 'undeclared' )
    By knave in forum C++ Programming
    Replies: 5
    Last Post: 05-10-2003, 05:41 PM

Tags for this Thread