Problem in <cmath>

salutations

this is my code :

int main()
{

cout<<"The square root of 25 is \t"<<sqrt(25)<<endl;





return 0;
}
_________________
this is an error :
error C2668: 'sqrt' : ambiguous call to overloaded function
____________________
and if i changed this line
cout<<"The square root of 25 is \t"<<sqrt(25)<<endl;
to this
cout<<"The square root of 25 is \t"<<sqrt(25.0)<<endl;
_________________________
an error will disappear.
____________-
i know this

<cmath>
returns a double value

but why when i let sqrt() receive int occurs an error?????????????

i mean this :

sqrt(25.0) = ture

sqrt(25) = false
______________________-
please help ...............

Last edited on
sqrt has many overloads - http://www.cplusplus.com/reference/clibrary/cmath/sqrt/ - so when you pass an int ( which can be implicitly casted to double, float and long double ) the compiler doesn't know which overload to call.
You need to pass it a number in one of these forms:
25.0 (double)
25.0l (long double)
25.0f (float)
thanks iam grateful......
If you are trying to do that, use a static cast for converting to double.
Topic archived. No new replies allowed.