Re: Real C++ compile problems
Re: Real C++ compile problems
- Subject: Re: Real C++ compile problems
- From: Heath Raftery <email@hidden>
- Date: Sun, 27 Jun 2004 11:00:21 +1000
On 27/06/2004, at 1:24 AM, Clark S. Cox ? wrote:
On Saturday, June 26, 2004, at 09:24AM, email@hidden
<email@hidden> wrote:
Thank you all for your initial help with Xcode and seeing the flaws
in my code. Sometimes when you write it yourself your blind to your
own mistakes.
But THIS time Im having a confusing error. My program compiles and
runs fine in unix, whereas in Xcode my errors are:
square.h:32: error: call of overloaded `sqrt(int)' is ambiguous
math.h:302: error: candidates are: double sqrt(double)
cmath:461: error: float std::sqrt(float)
cmath:465: error: long double std::sqrt(long double)
It looks like its having trouble with my sqrt calls. I dont know why
its saying the call is overloaded.
Also I didnt write the math.h or cmath.h programs, so I hope theres
no errors there.
The error is telling you that sqrt() accepts one of three types:
float, double or long double. When you pass it an int (as you do with
sqrt(2) ), the compiler doesn't know which one to call (int could be
promoted to any of those types). To solve this, pass one of the three
types that it is asking for. For instance, change "sqrt(2)" to
"sqrt(2.0)".
That's quite right, but just as a point of style, it is unnecessary to
call a function when all you need is a constant. If that value of 2 is
never going to change, you may want to do this instead:
const double SQRT_2 = 1.4142135623;
...
return SQRT_2*getSide();
But this is offtopic for the Xcode list, so I'll apologize and leave it
there ;)
Heath
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.