Thread: Classes

  1. #1
    Registered User
    Join Date
    Sep 2002


    Im currently reading a book called "Teach yourself C++ in 24 hours." Im on hour 7, and am not getting these classes. I dont understand entirely how they work, or why you would want to use them. Would it be a bad idea for me to skip over the chapter on classes? Or should i really know them before i continue? thanks.
    Im special

  2. #2
    CS Author and Instructor
    Join Date
    Sep 2002

    Thumbs up

    Yes-definitely -especially if you want to either become a programmer or major in CS.

    However, if this is just a hobby and you have no interest whatsever then you could skip it. Otherwise YES.
    Mr. C: Author and Instructor

  3. #3
    Registered User
    Join Date
    Sep 2002
    hehe i was afraid of that, thanks though, i appreciate it much.
    Im special

  4. #4
    Registered User
    Join Date
    Nov 2002
    If you skip them, you might as well stop learning C++. You'll need to know them. They are used for object-oriented purposes. Be sure to understand them before you continue. It will only lead to future confusion. Or you could skip, and do it the hard way.

  5. #5
    Registered User slaveofthenet's Avatar
    Join Date
    Apr 2003
    Classes are a very important part of C++, they are used everywhere. It can take a while to understand their sintax, but after that it shouldn't be too bad.

    >> I dont understand entirely how they work, or why you would want to use them.
    Let's say you want to store information for various rectangles, you can devise a class to store the data and functions to get/set the data.
    #include <iostream>
    using namespace std;
    class Rectangle
         Rectangle() { width = 0; height = 0; } /* constructor */
         void set_width(double w) { width = w; }
         void set_height(double h) { height = h; }
         double get_width() { return width; }
         double get_height() { return height; }
         double area() { return width*height; }
         double width, height, 
    }; /* don't forget the semicolon */
    int main()
         Rectangle my_rect;
         cout << "Width: " << my_rect.get_width() << '\n';
         cout << "Height: " << my_rect.get_height() << '\n';
         cout << "Area: " << my_rect.area() << endl;
         return 0;
    As you can imagine, classes can get quite more complex, but these are the basics.

  6. #6
    Registered User
    Join Date
    Apr 2003
    "I dont understand entirely how they work, or why you would want to use them."

    Do you think it might have anything to do with the book? The Sam's books aren't worth the paper they're printed on. The title should have been your first clue.

  7. #7
    Registered User dragon_man's Avatar
    Join Date
    May 2003
    You could probably learn more from bad internet tuts. I use to use Sams, it sucks

  8. #8
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    are you familiar with structured programming.. If not first lear that.. then move on to the theory of OOP's concept.. Then start classes...

  9. #9
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    I have that book, and yes its not that great but its decent enough.

    The problem is the classes arnt discussed via practical applicatiions the whole damn book is about cats and crap.
    basicly a CLASS is kinda like a template.

    I like to think of classes like MOLDS for clay or things that get poured and then harden. Basicly you create a mold and alteration tools like scrapers, paint brushes, etc. etc that will change or alter the orignal mold for custom look. Classes have tools called methods that allow you to set and access your slight modifications to an overal general mold.

    My explination probably isnt that good, but i assure you classes are something you must get a grasp on to become a solid programmer (and eventually get a job)
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  10. #10
    Registered User
    Join Date
    Sep 2002
    Ok, the book isnt helping me grasp it that well, does anyone have any links that explain classes well? Im gunna try the tutorial on this site right now.
    Im special

  11. #11
    i want wookie cookies the Wookie's Avatar
    Join Date
    Oct 2002
    well think of a class as a class room..with desks being functions and the people in the classroom being variables. a class is basically a way of grouping them together..supposed you just put an entire school (desks and kids) into a giant's less structured as opposed to putting them into classrooms

    classes basically group a bunch of functions and variables together so they can be used and accessed as one. it helps with organizing.

    like if you have a bike. one bike can be a class, with member functions being ride() and putdownstand(). you can have an array of these classes, like lets say

    class bike {
    //stuff here
    void ride();

    bike mybikeshop[50]; //i have 50 bikes

    and now i can access each bike individually much more easily, rather than having something like

    void ridebikeone()
    void ridebiketwo()

    hope that made sense

  12. #12
    Registered User major_small's Avatar
    Join Date
    May 2003
    wookie's analagy is nice, but leaves out the difference between public and private members...

    public members would be like the attendance office - they know where people are in the school, and visitors ( main() ) would go to the attendance office (a function in the public part of the class) to see/change/etc. the people in the classroom (stuff in the private part of the class). the people in the classroom can't be touched directly by anything except for what's in the public part. the public part is, well, public.

    in other words, the class protects data in the private area, and that data can only be accessed by functions in the public area, which can be called from main().
    Join is in our Unofficial Cprog IRC channel
    Channel: #Tech

    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  13. #13
    Registered User
    Join Date
    Sep 2002
    thanks guys im starting to get it now
    Im special

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 10:47 AM
  2. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 09:04 AM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  4. Exporting VC++ classes for use with VB
    By Helix in forum Windows Programming
    Replies: 2
    Last Post: 12-29-2003, 05:38 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM