How come sqrt() with which uses a calculation of two pow()'s inside of is wrong in intellisense

StackOverflow https://stackoverflow.com/questions/15649641

  •  29-03-2022
  •  | 
  •  

Question

I have this code:

int findY ( int x, int r) {

return sqrt(pow(x,2) - pow(r,2));

};

But for some reason Ms intellisense is flagging it as wrong syntax. I'm not sure why.

Was it helpful?

Solution

Look at the error it gives:

1>..\main.cpp(7): error C2668: 'pow' : ambiguous call to overloaded function
1>          C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\math.h(583): could be 'long double pow(long double,int)'
1>          C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\math.h(535): or       'float pow(float,int)'
1>          C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\math.h(497): or       'double pow(double,int)'
1>          while trying to match the argument list '(int, int)'

Basically, it's an ambiguous overload. So you need to cast it to clarify:

return sqrt(pow((double)x,2.) - pow(((double)r,2.));

Not only that, did you really intend the return type to be an int?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top