If I write a new function that has the signature of a C library function, I expect a compile error due to the ambiguity. But, I can't understand why there is no error in the following C++ code.
#include <iostream>
#include <cmath>
using namespace std;
double sqrt(double number)
{
return number * 2;
}
int main( )
{
cout << sqrt(2.3) << endl;
cout << ::sqrt(2.3) << endl;
cout << std::sqrt(2.3) << endl;
return 0;
}
If I change the return type of sqrt() to int, then a compile error occurs due to the declaration ambiguity with double sqrt() in cmath. How is it possible to override double sqrt()? (Actually, all the cmath functions can be overridden, and I don't know why.)