Implicit conversion rules
Maxim Fomin via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Oct 21 22:36:31 PDT 2015
On Wednesday, 21 October 2015 at 22:49:16 UTC, Marco Leise wrote:
> Am Wed, 21 Oct 2015 12:49:35 -0700
> schrieb Ali Çehreli <acehreli at yahoo.com>:
>
>> On 10/21/2015 12:37 PM, Sigg wrote:
>>
>> > cause at least few more "fun" side effects.
>>
>> One of those side effects would be function calls binding
>> silently to another overload:
>>
>> void foo(bool){/* ... */}
>> void foo(int) {/* ... */}
>>
>> auto a = 0; // If the type were deduced by the value,
>> foo(a); // then this would be a call to foo(bool)...
>> // until someone changed the value to 2. :)
>>
>> Ali
>
> God forbid anyone implement such nonsense into D !
> That would be the last thing we need that we cannot rely on
> the overload resolution any more. It would be as if making 'a'
> const would change the overload resolution when none of the
> overloads deal with constness...
>
AFAIK it was implemented long time ago and discussed last time
couple of years ago with example similar to Ali's.
void foo(bool)
void foo(int)
foo(0); // bool
foo(1); // bool
foo(2); // int
More information about the Digitalmars-d-learn
mailing list