alias not valid with ~

rikki cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jan 18 18:29:06 PST 2017


On 19/01/2017 3:25 PM, Adam D. Ruppe wrote:
> On Thursday, 19 January 2017 at 02:15:04 UTC, rikki cattermole wrote:
>> On 19/01/2017 3:08 PM, Ignacious wrote:
>>>
>>> class Y
>>> {
>>>    int y;
>>>    alias y this;
>>> }
>>>
>>> class X
>>> {
>>>    Y[] x;
>>>    alias x this;
>>> }
>
>> This should not fail:
>>
>> X x = new X;
>> x ~= 3;
>
>
> Yes, it should fail. 3 is not implicitly convertible to Y under any
> circumstance. D does not support implicit constructors.
>
> alias this only works if you ALREADY HAVE a Y, then it will implicitly
> convert Y to int. It will never go the other way around.

Oh Y, I read it as int, my bad.
Yes should fail.


More information about the Digitalmars-d-learn mailing list