C++ Classes

This is a discussion on C++ Classes within the C++ Programming forums, part of the General Programming Boards category; I am new to C++ and actually doing it as part of my Bsc degree, However the prescribed book 'c++ ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    1

    Question C++ Classes

    I am new to C++ and actually doing it as part of my Bsc degree, However the prescribed book 'c++ program design' is very hard to follow and frustrating. I am battleing with understanding Classes in particular declaring the class files. Although this site goes a long way to clarify the subject - my question is does anyone know of a site that may go a little deeper into the subject of classes etc?

    Thanks

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    70
    Ok, here's a quick lesson on classes. This is a class.
    Code:
    #include <iostream.h>
    class iwork //start out defining a class like this iwork can be substuted with any other name
    {
         public: //basically...for now...just put your functions in public, it's good practice
         //constructor
         iwork(); //don't really worry about this, just do it
         //functions going to be used in the class
         void test1(); //gathers the number
         void test2(); //outputs the contents of number gathered in test1();
         private:
         //variables going to be used ONLY in this class...this is important when you get into inheritance.
         int number;
    };//<-------note the semicolon
    iwork::iwork()
    {
         //just makes the constructor happy
    }
    void iwork::test1()
    {
         cout<<"Enter a number." <<endl;
         cin>>number;
         test2();
    }
    void iwork::test2()
    {
         cout<<"The number entered is:  " <<number <<endl;
    }
    main()
    {
         iwork inst; //creates an instance of the class so you can use it.
         inst.test1();
         return 0;
    }
    Please ask me any questions you may have...I'm still a newbie myself, but yea...I wanna help =) My AIM name is RevolutionST.

    Edit1: ......I'm on my way home from work, I'll elaborate when I get home.
    Edit2: I'm home now.
    Last edited by Extol; 10-07-2002 at 07:02 PM.

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, 11: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-24-2004, 12:22 AM
  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, 04:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21