C++ Need help with an error ...

Discussion in 'Mac Programming' started by Fender2112, Jan 25, 2006.

  1. macrumors 6502a

    Fender2112

    Joined:
    Aug 11, 2002
    Location:
    Charlotte, NC
  2. Moderator emeritus

    Mitthrawnuruodo

    Joined:
    Mar 10, 2004
    Location:
    Bergen, Norway
    #2
    Bare with me, it's been a couple of years since I've done this... :eek:

    Is this allowed without defining what the '=' should do for this class?

    Code:
    pavarotti = 265.8;
    taft = 325; 
    Also, if you'd wrap your code in code tags, so that indents would show, that would be nice... ;)
     
  3. macrumors 6502

    Joined:
    May 12, 2003
    #3
    That's the first thing that jumped out at me, too. You don't want to assign a new value to pavarotti and taft, you just want to modify the existing data.

    A more proper way would look like this:

    Code:
    pavarotti.setPounds(265.8);
    taft.setPounds(325);
    
    Of course, that won't work right away - you need to implement that functionality, which I will leave as an exercise to the reader.
     
  4. macrumors member

    Joined:
    Sep 23, 2004
    Location:
    Redwood City, CA
    #4
    As a general C++ programming rule of thumb, when you first stub out your class skeleton always disable your copy constructor and assignment operator. This way any misuse will be caught at compile time. This will save you many headaches. Happy coding!
     
  5. macrumors 601

    zimv20

    Joined:
    Jul 18, 2002
    Location:
    chicago
    #5
    i agree, it's the "pavarotti = 265.8;" and similar lines that are getting you. comment them out to confirm.

    to properly handle that statement, you need to write a function for your assignment operator.

    (i haven't coded C++ since about '97; funny how it just comes back like that)
     
  6. macrumors 6502a

    #6
    Code Errors:

    poundsLeft = int (lbs) % poundsPerStone //+ lbs - int(lbs);
    You have commented out the ';'

    void Stonewt::showPounds()
    You have declared but not defined showPounds() as const

    Runtime Error:
    I guess you are not compiling stonewt.cpp. In Xcode and assuming a project called Stonewt under "Groups and Files" (left hand pane in project window) expand Target > Stonewt > Compile Sources. Is stonewt.cpp there? If not drag it over from the Stonewt > Source.

    The programme is expecting to find some binary implementation of the class Stonewt at run time and you are not providing it.
     
  7. thread starter macrumors 6502a

    Fender2112

    Joined:
    Aug 11, 2002
    Location:
    Charlotte, NC
    #7
    Error found

    Found the problem:

    File 2 - methods file
    void Stonewt::showPounds() const

    left off the const
     

Share This Page