Tue, 13 Jan 2009 05:59:58 +0900, Bill Baxter wrote: > On Tue, Jan 13, 2009 at 1:48 AM, Sergey Gromov <snake.sc...@gmail.com> wrote: > >> However, with a typedef, LocalType is a distinct type. Yes it casts to >> int implicitly, but likewise it casts implicitly to char, short and >> long. So compiler gets a whole load of File.write() functions matching >> with conversions, and fails because of the ambiguity. >> >> That's how the language works, and it's pretty consistent IMO. What you >> can do is: > > But the difference is LocalType can be converted to int exactly in all > cases. Given a choice of int,char,short,etc. clearly the conversion > to int is best choice. It may be consistent with other cases > involving multiple legal conversions, but usually you don't have such > a single clearly preferred conversion. It seems to significantly > reduce the utility of typedef.
It's about overload resolution rules. The specs say: The levels of matching are: * no match * match with implicit conversions * exact match There is no notion of 'best' implicit conversion.