Thread: 2 errors in my code

  1. #16
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    I have a few comments!

    - The Rectangle class needs a destructor, since you wrote a constructor.
    - You should use your getter functions to compose the equation in your area function.
    - The Cube class inherits the height variable, you dont need to make another private member for the Cube class. The Cube class can also simply use Rectangle's implementation, since nothing is different about it. Save yourself the typing.

    Most importantly, default parameters belong in the implementation of the constructor:
    Code:
    Rectangle::Rectangle(double l=0., double w=0.) : length(l), width(w) 
    { }
    And of course the loop will be endless until the user types something that isn't 1 or 2. Type 0, for instance, and the loop breaks.
    Last edited by whiteflags; 05-03-2006 at 11:02 PM.

  2. #17
    Registered User
    Join Date
    Feb 2006
    Posts
    20
    forget the loop any idea why the functions wont take the numbers and they are producing garbage?

  3. #18
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    No matter what the user passes into your Rectangle constructor, you ignore it and use zeros, for one thing.

    Use the constructor I built for you in my last post. They don't have the same variable names as yours does, but that can be easily changed. I tested my constructor before posting it and it works fine.

  4. #19
    Registered User
    Join Date
    Feb 2006
    Posts
    20
    your constructor gives me 2 errors:

    .\Rectangle.cpp(4) : error C2572: 'Rectangle::Rectangle' : redefinition of default parameter : parameter 2
    c:\documents and settings\johnnyg\my documents\visual studio 2005\projects\project 8\project 8\Rectangle.h(8) : see declaration of 'Rectangle::Rectangle'
    .\Rectangle.cpp(4) : error C2572: 'Rectangle::Rectangle' : redefinition of default parameter : parameter 1
    c:\documents and settings\johnnyg\my documents\visual studio 2005\projects\project 8\project 8\Rectangle.h(8) : see declaration of 'Rectangle::Rectangle'

    thats the way i had it at the start but had to remove those due to the errors it was causing... seemed to be unavoidable
    Last edited by johnnyg; 05-04-2006 at 12:23 AM.

  5. #20
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    I will do this for you again. I told you my parameter names didn't match yours; you would need to change them--and that's what those errors mean.
    This will definitely work.
    Code:
    Rectangle::Rectangle (double l=0., double w=0.) : length(l), width(w) { }
    Last edited by whiteflags; 05-04-2006 at 12:31 AM.

  6. #21
    Registered User
    Join Date
    Feb 2006
    Posts
    20
    they give me the same two errors
    sorry -_-

  7. #22
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    Sorry, I went to sleep. What exactly is the problem again as it seems we've gone off on a tangent.

  8. #23
    Registered User
    Join Date
    Feb 2006
    Posts
    20
    well i have to leave to turn it in now but the problem was the var's arnt being set by the user input and are just returning garbage.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  2. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Linux Programming
    Replies: 0
    Last Post: 10-14-2002, 01:30 PM
  3. RAM/Swap Memory Code Errors
    By ghe1 in forum Linux Programming
    Replies: 2
    Last Post: 04-01-2002, 07:37 AM
  4. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 12:51 PM