constness for arrays

Ben Phillips Ben_member at pathlink.com
Fri Jul 21 13:05:18 PDT 2006


>
>operator "="  IS really necessary.  As there is no method in D
>currently to guard assignment to variable (memory location).
>Again without it good chunk of RAII methods and smart pointers
>are not implementable in D.
>

It is impossible to allow operator "=" to be overloaded without totally killing
the way D works because D uses references.
Example:
ClassA a = new ClassA();
ClassA b = a; // b now refers to a
b.mutate(); // both 'b' and 'a' are changed since they refer to the same object

What is possible is to define a new operator (such as ":=") that means copy
assignment, but I don't see how this differs from creating a method that does
the same thing.





More information about the Digitalmars-d mailing list