Preventing implicit conversion

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Nov 4 21:41:35 PST 2015


On Wednesday, November 04, 2015 21:22:02 ixid via Digitalmars-d-learn wrote:
> On Wednesday, 4 November 2015 at 19:09:42 UTC, Maxim Fomin wrote:
> > On Wednesday, 4 November 2015 at 14:27:49 UTC, ixid wrote:
> >> Is there an elegant way of avoiding implicit conversion to int
> >> when you're using shorter types?
> >
> > Only with library solution. Implicit conversions are built into
> > language.
>
> Doesn't that seem rather limiting and unnecessary?

Why? You can't affect what conversions do and don't work for the built-in
types in _any_ language that I've ever used, and I've never heard of a
language that allowed anything like that. If you want different conversion
rules, you need to create a user-defined type that defines the conversions
you want. That's pretty normal.

And AFAIK, there aren't very many folks trying to avoid the built-in
implicit conversions in D, particularly since D eliminated the various
implicit narrowing conversions that you get in C/C++.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list