Overloading the assignment operator, right now!
Oskar Linde
oskar.lindeREM at OVEgmail.com
Fri Sep 15 00:43:07 PDT 2006
Derek Parnell wrote:
> On Thu, 14 Sep 2006 17:30:29 +0300, Georg Wrede wrote:
>
>> Overloading of the assignment operator is not allowed in D.
>>
>> But no problem, we can do it right now, in spite of it.
>
> I'm happy to not have the assignment operator overloaded in D.
For classes I agree. Overloading reference assignment doesn't make much
sense. For structs on the other hand, assignment means (shallow) copying
and being able to define that behavior would be useful.
>
> I'm unhappy that D doesn't have a copy operator. If it did, I'd like to
> overload that!
But in a way it does have one such operator. I am thinking about []=.
struct Matrix {
T* ptr;
size_t w,h;
...
Matrix opSliceAssign(Matrix b) {...}
}
Matrix a,b;
...
a=b; // Makes a refer to the same memory as b
a[]=b; // Copies the contents of b to a
/Oskar
More information about the Digitalmars-d
mailing list