opAssign in D2

BCS ao at pathlink.com
Mon Jun 2 11:34:03 PDT 2008


Reply to Koroskin,

> On Mon, 02 Jun 2008 20:08:29 +0400, lurker <lurker at lurker.com> wrote:
> 
>> hi,
>> 
>> i like to copy objects such as:
>> 
>> class A {....}
>> 
>> A xxx; // some things are done ...
>> 
>> A yyy = xxx;
>> 
>> how can one do that in D2 easy? are any samples?
>> 
>> thanks
>> 
> You shouldn't use this for by design, it's not supported for reference
> types, only for structs.
> But you might consider wrapping the class into a struct with
> overloaded
> opAssign semantics.
> It sould work fine for you (after opImplicitCast is implemented :)).
> The other limitation of opAssign is that you can't override opAssign
> to  accept object of the same type:
> 

It's not really clean but making a dup() method would be constant with D's 
arrays.




More information about the Digitalmars-d-learn mailing list