| farooroo (9) | |
|
int find_length(int *A,int n){ int i,sum=0; int length; for(i=0;i<n;i++) sum+=A[i]*A[i]; length= sqrt(sum); return length; } it keeps giving me this error: 'sqrt' : ambiguous call to overloaded function could be 'long double sqrt(long double)' 'float sqrt(float)' 'double sqrt(double)' | |
|
|
|
| Moschops (5961) | ||
The function sqrt does not take an int. You are trying to give it an int. Your compiler has three sqrt functions it knows about (more recent compilers have more). One takes a float. One takes a double. One takes a long double. The compiler is not psychic. It cannot guess which of these functions you actually meant to use. You will have to tell it. | ||
|
Last edited on
|
||
| farooroo (9) | |
|
thanks I got it! i just did sqrt (double(sum)); thanks :) | |
|
|
|
| JLBorges (1336) | |||
|
This will compile cleanly in C++11. C++98: length = std::sqrt( double(sum) ) ;Make find_length() const-correct. And consider if the result type should be a floating point value.find_length()? Or should it be root_sum_square()?
| |||
|
Last edited on
|
|||