View Full Version : C++ Need help with an error ...

Jan 25, 2006, 08:14 PM
I am having a little trouble. Here are the details (http://www.xcodeforums.com/forum/viewtopic.php?t=89).

Jan 25, 2006, 08:28 PM
Bare with me, it's been a couple of years since I've done this... :o

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

pavarotti = 265.8;
taft = 325;

Also, if you'd wrap your code in code tags, so that indents would show, that would be nice... ;)

Jan 25, 2006, 10:47 PM
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:


Of course, that won't work right away - you need to implement that functionality, which I will leave as an exercise to the reader.

Jan 26, 2006, 01:06 AM
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!

Jan 26, 2006, 01:54 AM
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)

Jan 26, 2006, 04:33 AM
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.

Jan 26, 2006, 04:28 PM
Found the problem:

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

left off the const