Problem with the pow( ) function [modified]
-
Hi, 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: cmath and math.h but the error message remained the same. What is the cause of the error? I've checked the syntax and it seems correct. -- modified at 13:30 Wednesday 19th July, 2006
-
Hi, 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: cmath and math.h but the error message remained the same. What is the cause of the error? I've checked the syntax and it seems correct. -- modified at 13:30 Wednesday 19th July, 2006
KaKa` wrote:
There was an error message about the power function when I compiled the code. It is: error c2668: 'pow' :ambiguous call to overloaded function.
Apparently there's more than one
pow()
function. Which one do you want to use?
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
-
Hi, 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: cmath and math.h but the error message remained the same. What is the cause of the error? I've checked the syntax and it seems correct. -- modified at 13:30 Wednesday 19th July, 2006
how is defined the data matrix (what type) ? i think it contains values other than
int
, that's why the compiler doesn't know which function to call (pow(int, int)
orpow(double, double)
?? ).
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
Hi, 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: cmath and math.h but the error message remained the same. What is the cause of the error? I've checked the syntax and it seems correct. -- modified at 13:30 Wednesday 19th July, 2006
-
Hi, 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: cmath and math.h but the error message remained the same. What is the cause of the error? I've checked the syntax and it seems correct. -- modified at 13:30 Wednesday 19th July, 2006
-
If you couldn't figure out the problem, why don't you write your own pow() function? It's simple...
cppcook wrote:
If you couldn't figure out the problem, why don't you write your own pow() function? It's simple...
Simple for integer exponents ... not so simple for decimal exponents. As for the original post, my guess is that you are mixing types (that is, raising a double by an integer power). While there is nothing wrong with that, pow is usually defined: From MSDN:
double pow( double x, double y ); double pow( double x, int y ); // C++ only double pow( int x, int y ); // C++ only float pow( float x, float y ); // C++ only float pow( float x, int y ); // C++ only long double pow( long double x, long double y ); // C++ only long double pow( long double x, int y ); // C++ only float powf( float x, float y );
Try explicitly casting your types:
double base = 3.0; int power = 5; int result = pow(base, (double)power);
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
-
Hi, 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: cmath and math.h but the error message remained the same. What is the cause of the error? I've checked the syntax and it seems correct. -- modified at 13:30 Wednesday 19th July, 2006
Is a result of implicit casts being available. Explicitly case each parameter to the datatype to use that matches one of the pow formal parameter lists. A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane
-
Hi, 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: cmath and math.h but the error message remained the same. What is the cause of the error? I've checked the syntax and it seems correct. -- modified at 13:30 Wednesday 19th July, 2006
-
If you know nothing about function overloading just cast both parameters to (double) and it will compile.
tempDistance += pow(((double)data[selectedInstance][k]-data[j][k]),2.0);