Question:
pow() error in Visual C++ 2005?
ZhiYi
2006-07-19 10:49:49 UTC
I am using Visual C++ 2005 to write code a win32 console application.

There was an error message about the power function when I compiled the code. It is: error c2668: 'pow' :ambiguous call to overloaded function.

The statement is:

tempDistance += pow((data[selectedInstance][k]-data[j][k]),2);

I used various headers like:

, and but the error message remained the same.

What is the cause of the error? I've checked the syntax and it seems correct.
Five answers:
agent-X
2006-07-19 11:01:47 UTC
double pow(double x,double y) (from math.h); there you also have powf (for float) and powl ofr long double); Check how you declared tempDistance and the array! The compiler doesn't know what conversion to apply in your case...
sideshot72
2006-07-19 10:57:01 UTC
Double check the data type of your argument to the pow() function. There is likely more than one overload of pow() that will do what you want, but the compiler can't decide which one to use. Just stick and explicit cast in there and be done with it. To wit:



pow( double(data[selectedInstance]........



Note the insertion of a double() constructor!



Or use old-fashioned C-style cast:

(double)(arg)
Alyssa
2006-07-19 10:58:23 UTC
Here is what I'm finding as the problem, pow(int, int) has been removed from math.h.



1. Look at the data type of your arguments.

2. Look at the data type of your variable. (tempDistance)



The compiler is trying to figure it what to use when it just can't.



if you haven't written overloaded functions yet the error might not make much sense to you.



(Remember that pow(int,int) is gone. )
Erika
2016-10-15 03:17:26 UTC
does it say what line the mistakes is on? what are you attempting to do? output all those stars? thats trouble-free. yet idk abotu stdafx.h ive under no circumstances used that part of your code. and for my section i favor no longer to apply the "<> instead of cout<< or think about only a million < instead of two. that could favor to cover all of your blunders.
Katie Wady
2006-07-19 10:51:47 UTC
What?


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...