How come I can't use 'sqrt' and 'fabs'?

V

Vol

Hi, group,
When I compile my code, the error message are:
"error C2668: 'fabs' : ambiguous call to overloaded function"
"error C2668: 'sqrt' : ambiguous call to overloaded function"

I already add the math library, what does this error mean? Thanks.

Vol.
 
F

Flash Gordon

Vol said:
Hi, group,
When I compile my code, the error message are:
"error C2668: 'fabs' : ambiguous call to overloaded function"
"error C2668: 'sqrt' : ambiguous call to overloaded function"

I already add the math library, what does this error mean? Thanks.

It probably means you are not compiling C code (or as C) since C does
not have overloaded functions.

If this is meant to be C post a *complete* small program exhibiting the
problem, if it is C++ then go to a group dealing in C++ such as
comp.lang.c++

Alternatively delete lines 4, 30, 43 to 1000 inclusive and 1002, destroy
all other copies of your program, and try again.
 
M

Michael Mair

Vol said:
Hi, group,
When I compile my code, the error message are:
"error C2668: 'fabs' : ambiguous call to overloaded function"
"error C2668: 'sqrt' : ambiguous call to overloaded function"

I already add the math library, what does this error mean? Thanks.

That you are not using a C compiler but probably a C++ compiler
to compile your code. So, your best bet is asking this question
in comp.lang.c++ as it is definitely off-topic and irrelevant
here.

<OT>You are probably passing an integer argument to functions which
are overloaded to have arguments of either type double, or type float
or type long double. This is a Bad Thing, as the compiler tries
to determine the best overloaded function -- and may use different
overloads at different places. This can result in irreproducible
behavior if the source code changes but slightly.
If you use literals, pass one of the right type, e.g.
2.0
2.0F
2.0L
instead of
2
For variables, use an appropriate static_cast<>() (not a C cast!!):
static_cast<double>(my_integer_argument)
</OT>


Cheers
Michael
 
M

Martin Ambuhl

Vol said:
Hi, group,
When I compile my code, the error message are:
"error C2668: 'fabs' : ambiguous call to overloaded function"
"error C2668: 'sqrt' : ambiguous call to overloaded function"

I already add the math library, what does this error mean? Thanks.

Before posting to any newsgroup check the FAQ.
 
M

Michael Mair

Michael said:
That you are not using a C compiler but probably a C++ compiler
to compile your code. So, your best bet is asking this question
in comp.lang.c++ as it is definitely off-topic and irrelevant
here.

<OT>You are probably passing an integer argument to functions which
are overloaded to have arguments of either type double, or type float
or type long double. This is a Bad Thing, as the compiler tries
to determine the best overloaded function -- and may use different
overloads at different places. This can result in irreproducible
behavior if the source code changes but slightly.
If you use literals, pass one of the right type, e.g.
2.0
2.0F
2.0L
instead of
2
For variables, use an appropriate static_cast<>() (not a C cast!!):
static_cast<double>(my_integer_argument)
</OT>

This is the C++ solution.

If you wanted C: Use a C compiler!
 
K

Keith Thompson

Martin Ambuhl said:
Before posting to any newsgroup check the FAQ.

That's always good advice, but I don't see how the C FAQ answers this
particular question.
 
M

Mark McIntyre

Hi, group,
When I compile my code, the error message are:
"error C2668: 'fabs' : ambiguous call to overloaded function"
"error C2668: 'sqrt' : ambiguous call to overloaded function"

I already add the math library, what does this error mean? Thanks.

You're invoking the C++ compiler perhaps?

This is strictly speaking a compiler-specific problem, you may have
more luck in a compiler specific newsgroup.
 
D

Default User

Mark said:
You're invoking the C++ compiler perhaps?

The post you are replying to was from four days ago and the OP received
the same answer from two other people at the time.



Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,170
Messages
2,570,925
Members
47,466
Latest member
DrusillaYa

Latest Threads

Top