Thread: Having Trouble Understanding Classes

  1. #1
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820

    Question Having Trouble Understanding Classes

    Hey guys i have been trying to get classes down for a while i just can't to seem to get it. I understand how to use data types but i just can't get the function parts.
    A few questions:
    What is the point of having the functions in there?
    What is the point of the public,private,protected?(kinda get these but not fully)
    Im sorry if these seem dumb this stuff just doesn't seem to register with me and any example code would be nice to see
    Woop?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >What is the point of having the functions in there?
    A class is a data type. It has data, and the necessary operations that can be performed on the data. Look at it this way, if int only had the storage for an integer but no operations, it would be a real pain to add numbers, wouldn't it?

    >What is the point of the public,private,protected?
    You can make more assumptions and guarantee more if access is restricted only to code that knows how to keep things nice and tidy. Access control is meant to improve the reliability of code by ensuring that only "authorized" code can read or write important data. You wouldn't want everyone around you to be able to see and fiddle with your privates, would you?

    >Im sorry if these seem dumb
    Hardly. These are excellent questions that beg to be asked. Don't be afraid to ask questions, it's a better way to learn than making mistakes all of the time (though not necessarily more effective ).
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bolean Operators hurt my head. (Trouble understanding) :(
    By Funcoot in forum C++ Programming
    Replies: 3
    Last Post: 01-20-2008, 07:42 PM
  2. trouble understanding the source file structure
    By Mario F. in forum C++ Programming
    Replies: 5
    Last Post: 05-26-2006, 06:46 PM
  3. Classes being able to use other classes functions
    By rainmanddw in forum C++ Programming
    Replies: 6
    Last Post: 01-29-2006, 11:19 AM
  4. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM
  5. Sharing a variable between classes of different .CPP files
    By divingcrab in forum C++ Programming
    Replies: 5
    Last Post: 07-07-2002, 02:57 PM