Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Mitthrawnuruodo

Moderator emeritus
Mar 10, 2004
14,657
1,465
Bergen, Norway
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... ;)
 

therevolution

macrumors 6502
May 12, 2003
468
0
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.
 

steeveage

macrumors member
Sep 23, 2004
39
0
Redwood City, CA
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!
 

zimv20

macrumors 601
Jul 18, 2002
4,402
11
toronto
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)
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.