TITLE: function overload resolution PROBLEM: Juhani.Polvinen@fmi.fi (Juhani Polvinen) We just found a weird error in our code: We have overloaded a function: foo(short i, char* bar ="xxx"): foo(float b, char* bar ="yyy"): we call it with foo(b): It seems that different compilers (we have tried BC++, Mac Symantec and VC++) treat that signature diffrently. ... RESPONSE: clamage@Eng.Sun.COM (Steve Clamage), 13 Nov 95 You don't say what the type of 'b' is in the call. That makes all the difference, although there isn't room for variation in compiler behavior. If b is type short, the first foo must be called. If b is type float, the second foo must be called. If b is a class type with a conversion to short but not to float, the first foo must be called. If b is a class type with a conversion to float but not to short, the second foo must be called. If b fits none of the above cases (e.g., it is any numeric or enum type other than short or float), the call is in error, due either to no match or to ambiguity. The reason for ambiguity is that there is no promotion to either short or float, so from other numberic or enum types there would be a standard conversion. No standard conversion is preferred over any other, so a call like foo(1) or foo(1.0) is ambiguous. If you change 'short' to 'int', and change 'float' to 'double', you will remove the ambiguity for the most common cases (any flavor of char, signed or unsigned short, signed int, float, double, and any enum with an underlying type of int or smaller). Some cases will remain ambiguous (unsigned int, long, unsigned long, long double, enum with an underlying type of unsigned int, long or unsigned long, and some class types depending on what conversions they have).