I\'m working on a C++ program for class, and my compiler is complaining about an \"ambiguous\" function call. I suspect that this is because there are several functions defined
The abs
function included by
is overloaded for int
and long
and long long
. Since you give a double
as the argument, the compiler does not have an exact fit, so it tries to convert the double
to a type that abs
accepts, but it does not know if it should try to convert it to int
, long
, or long long
, hence it's ambiguous.
But you probably really want the abs
that takes a double
and returns a double
. For this you need to include
. Since the double
argument matches exactly, the compiler will not complain.
It seems that
gets included automatically when you include the other headers which should not happen. The compiler should have given error: ‘abs’ was not declared in this scope
or something similar.