Constructor params with same name as members

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Oct 24 05:54:39 PDT 2014


On 10/23/14 3:22 PM, "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm at gmx.net>" 
wrote:
> On Thursday, 23 October 2014 at 18:57:33 UTC, Ali Çehreli wrote:
>> On 10/22/2014 11:37 PM, Jonathan M Davis wrote:
>>
>> > x = x;
>> >
>> > which is so obviously wrong that I don't know how much of
>> anyone could
>> > make that mistake. But simply making it illegal to assign a
>> variable to
>> > itself would solve that problem, and that arguably should be
>> done, since
>> > it's a essentially a no-op.
>>
>> Steve said the same thing and it's true for fundamental types but just
>> to annoy you two, assignment can have side effects. :)
>
> But it wouldn't be a no-op then.

Was about to say the same thing :)

I think the compiler might be able to tell the difference between x = x; 
when x is an int and x is a struct with opAssign.

-Steve


More information about the Digitalmars-d-learn mailing list