www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - opAssign: a suggestion

How about allowing overloading of opAssign as long as the type of the right hand
side is not the same as the type of the left hand side. In this way a normal
assignment will still always just copy the reference as is the case at the
moment. This will help a lot when writing container classes.


class A
B data;
void opAssign(A a) {  // ERROR: rhs same type as lhs
.. }
void opAssign(B b) P  // OK!
data = b; }


Apr 24 2005