opAssign in D2

BCS ao at pathlink.com
Mon Jun 2 09:15:05 PDT 2008

Reply to lurker,

> 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

first, classes are reference types so the above needs to be:

A xxx = new A;
 // some things are done ...
A yyy = xxx;

second, that assignment will work as is but will act as a reference copy 
(you get two copies of the reference to the same object). If you want a real 
copy you can use structs or generate a deep copy function for the class. 
I don't use 2.0 so someone else will need to fill in the details.

More information about the Digitalmars-d-learn mailing list