Thread: Why Classes??

  1. #1

    Question Why Classes??

    I have read about using Class But I doesn't understand Why to use Class??
    I mean if I will creat a Class that contain 2 funcs and 5 varibles
    what will be worse if I creat 2 func and 5 varibles outside a class
    and not useing class???
    [ I does not refuse using Classes But doesn't understand Why?]

  2. #2
    Join Date
    Feb 2002
    Because classes help you see programming-type problems in a "real world" way - for example, it is more "natural" to have an account object in a banking application that handles it's own withdrawal and deposit methods than to have that code scattered around in various places. Also, classes encapsulate, or hide code from a user of the class, so that in theory it is easy to upgrade the code for a class without "breaking" the code that uses it.

    Visit - It's what your PC is made for!

  3. #3
    Registered User
    Join Date
    Apr 2002
    Because if you 'write' a class to do a specific task(such calculate the surface of a circle) and you need it someday in another project, well the class you've wrtie will work in any programs.... if you don't do it in a class, well you'll have to re-write everything to make it fit into your program....

    a class is reusable...

  4. #4
    Join Date
    Feb 2002
    ....and if you write it properly, to allow you to inherit it, to allow you to use it to calculate the area of a square, or rhomboid, or whatever.
    Visit - It's what your PC is made for!

  5. #5
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    One nice thing is that you can do this:

    class c {
    int anint;
    char array[50];
    void func();
    int func2(int a);
    //and then do
    c classarray[50];
    //instead of creating 50 of each variable and function

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. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM