Classes need help

This is a discussion on Classes need help within the C++ Programming forums, part of the General Programming Boards category; I have a project I'm working on for my C++ class. It's just a simple project to show that I ...

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    2

    Unhappy Classes need help

    I have a project I'm working on for my C++ class. It's just a simple project to show that I know how to use OO programming.

    Here's my problem...

    The project requires 2 constructors one that take a double argument to initialize "dRadius" and the other dose not take any arguments, it just sets "dRadius" to 0. The project also requires another function that sets "dRadius". There is no user interaction for this project. So why have a constructor and a function that do the same thing? Is it good programming to initialize a class member 2 time in a row?

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Its conceivable that you might want to modify this variable later, and hence the other function. The constructors guarantee that it does get initialized, and allows you to do so with a specified value. The only initializing is done in the constructors. After that, it is just modifying it. Also, it allows you to construct the object and set it at the required value, instead of setting it to some default value, and then setting it to something else (which can be costly if your data member is a large, user-defined tyep... though for a primitive type such as an int, it really doesn't matter).

    In short, it is perfectly acceptable programming practice.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    2
    Thanks for the reply that is what I wanted to know.

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, 08: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, 04:38 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM

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