f



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

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.

0
volunteers (55)
10/22/2005 7:03:53 AM
comp.lang.c 30657 articles. 3 followers. spinoza1111 (3246) is leader. Post Follow

7 Replies
707 Views

Similar Articles

[PageSpeed] 41

Vol wrote:
> 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.
-- 
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
0
spam331 (4048)
10/22/2005 9:47:00 AM
Vol wrote:
> 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
-- 
E-Mail: Mine is an   /at/ gmx /dot/ de   address.
0
Michael.Mair (1492)
10/22/2005 9:57:07 AM
Vol wrote:
> 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.
0
mambuhl (2202)
10/22/2005 10:00:44 AM
Michael Mair wrote:
> Vol wrote:
> 
>> 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>

This is the C++ solution.

If you wanted C: Use a C compiler!

> 
> 
> Cheers
>  Michael


-- 
E-Mail: Mine is an   /at/ gmx /dot/ de   address.
0
Michael.Mair (1492)
10/22/2005 10:01:02 AM
Martin Ambuhl <mambuhl@earthlink.net> writes:
> Vol wrote:
>> 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.

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

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center             <*>  <http://users.sdsc.edu/~kst>
We must do something.  This is something.  Therefore, we must do this.
0
kst-u (21963)
10/22/2005 5:09:41 PM
On 22 Oct 2005 00:03:53 -0700, in comp.lang.c , "Vol"
<volunteers@gmail.com> wrote:

>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. 
-- 
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
0
markmcintyre (4555)
10/26/2005 7:44:25 PM
Mark McIntyre wrote:

> On 22 Oct 2005 00:03:53 -0700, in comp.lang.c , "Vol"
> <volunteers@gmail.com> wrote:
> 
> > 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?  

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
0
defaultuserbr (3657)
10/26/2005 9:06:47 PM
Reply: