using a typedefed variable with library classes

Bill Baxter wbaxter at gmail.com
Mon Jan 12 12:59:58 PST 2009


On Tue, Jan 13, 2009 at 1:48 AM, Sergey Gromov <snake.scaly at 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.

--bb


More information about the Digitalmars-d-learn mailing list