From http://digitalmars.com/d/1.0/operatoroverloading.html
The assignment operator cannot be overloaded for rvalues that can be implicitly cast to the lvalue type.
Doing so results in a compiler error.
But doing it via an alias, the compiler does not complain.
class C{
C set( C c ){ return c; }
alias set opAssign;
}
Comment #1 by smjg — 2008-09-09T16:21:48Z
The compiler accepts the code, but the assignment operator doesn't actually overload:
----------
import std.stdio;
class C {
C set(C c) {
writefln("Calling C.set");
return c;
}
alias set opAssign;
}
void main() {
C d = new C;
C e = new C;
d = e;
}
----------
generates no output on run.
Comment #2 by pro.mathias.lang — 2019-07-16T04:09:50Z
The compiler gives an error ("class `mod.C` identity assignment operator overload is illegal") in D2.