How do you make a copy TO and object when you're INSIDE of it?

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 24 07:44:32 PDT 2015


On Friday, 24 July 2015 at 14:12:54 UTC, Steven Schveighoffer 
wrote:
> On 7/24/15 4:47 AM, "Marc =?UTF-8?B?U2Now7x0eiI=?= 
> <schuetzm at gmx.net>" wrote:
>> Apart from what others have said, for a class `this` is the 
>> _reference_
>> to the current object, i.e. a "pointer". If the compiler 
>> allowed
>> assigning to it, it would not modify the contents of your 
>> object.
>>
>> If you want to assign all of the elements at once, you can use 
>> `tupleof`
>> (untested):
>>
>>      this.tupleof = other.tupleof;
>
> I'm quite certain this wouldn't copy the derived data. So be 
> careful when doing this, you can only do this on final classes.

Right, this is dangerous for classes.


More information about the Digitalmars-d-learn mailing list