Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jun 2003
    Location
    California
    Posts
    231
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question CPP..why make new objects?

    I'm reading about classes and instances and I dont think I understand why anyone would need to make new objects..Doesn't C++ have enough objects to make the cpp do pretty much anything you'd want to do?

  • #2
    Regular Coder
    Join Date
    Feb 2004
    Location
    WA
    Posts
    213
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Think of it this way: All the objects that are generic enough and that can be used in a lot of places are already written and are available as standard libraries, or 3rd party libraries. All the objects that are specific to the scenario are the ones that are being written everyday by programmers.

    For example: you are making a program to control a special device you made. lets say that the device makes baloons by taking rubber as input and several parameters, like color, design, etc to make its output. so you now have an object that represents this device. its members look like outputcolor, outputdesign, etc. Surely, no one else cares about this object.. you have to write it yourself!
    Nobody is Perfect. I am Nobody.

  • #3
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Very well said Unit!

    Indeed they are very useful, you need new objects because CPP doesn't have the particular object for everything!

    Like I've been making custom gui controls, I need to keep track of different properties like say if it's a button, the style, is it clicked? what color is it and what does it have written on it? Although, I tend to use structs more unless I need member functions..

    What I really find useful with classes is derived an templated classes though, templated classes are very useful for lists and memory management and derived classes make making a wrapper for my controls like that of MFC easier.

    C++ doesn't have built in objects really, they're all created in standard libraries as said ... You'll always need new objects.

    [edit:] Welcome to the forums Unit
    Omnis mico antequam dominus Spookster!

  • #4
    New Coder
    Join Date
    Mar 2004
    Location
    Durham, UK
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Think if you want to have a list of employees. There is no employee class, but it would be useful to have an employee object for each employee to hold together their data and the methods to view and alter it too.

  • #5
    Regular Coder
    Join Date
    Feb 2004
    Location
    WA
    Posts
    213
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OT:
    Originally posted by Mhtml
    [edit:] Welcome to the forums Unit
    Thanks! I am not new to these forums though I was a regular member long time back, maybe 3 or 4 years back at wsabstract. I discontinued posting due to personal pressures, but I am back

    I lost all touch with Javascript, so I am lurking around posting only things that I know for sure
    Nobody is Perfect. I am Nobody.

  • #6
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    lol ... well I'm sure given time you'll be back in the saddle so to speak ..
    Omnis mico antequam dominus Spookster!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •