2 errors in my code

This is a discussion on 2 errors in my code within the C++ Programming forums, part of the General Programming Boards category; I have a few comments! - The Rectangle class needs a destructor, since you wrote a constructor. - You should ...

  1. #16
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,758
    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-04-2006 at 12:02 AM.

  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
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,758
    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 01:23 AM.

  5. #20
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,758
    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 01: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
    University of Waterloo
    Posts
    1,904
    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.

Page 2 of 2 FirstFirst 12
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, 02: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

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