First, do not use using namespace std; . In this case, there is a structure called std::plus -oh, wait, no matter what is actually called plus and its constructor is thrown into the bucket to allow overloading using the plus function.
Secondly, you have ambiguity, because 3.2 and 4.2 are of type double and can convert equally well to float or int .
This is a simplification, but when it comes to passing numbers to an overloaded function, C ++ basically uses these rules:
- If all arguments exactly match one of the overloads, use this one.
- If all arguments can be raised to fit one of the overloads, use this one.
- If all arguments can be numerically converted to match one of the overloads, use this one.
If you have several candidates at a certain level, then this is ambiguity. Rarely, a double does not advance to float , which would be a drop. Therefore, it should use the standard conversion in float , which is associated with the standard conversion with int , so these two overloads are ambiguous.
John calsbeek
source share