The table states that classes do not overload the assignment operator. However this code compiles: class A { int a; string b; float c; void opAssign(B b) { a = b.a; } } class B { int a; } void main() { auto a = new A(); a.a = 5; auto b = new B(); b.a = 10; a = b; assert(a.a == 10); }
Forgot the pages: http://www.d-programming-language.org/struct and this one only mentions struct: http://www.d-programming-language.org/operatoroverloading.html#Assignment
No, the code isn't invalid, the documentation is just bad. identity assignment overloading is not allowed for classes, that is what the table is alluding to: class A { void opAssign(A a) {} } Error: function testassign.A.opAssign identity assignment operator overload is illegal There are several other places in the spec that could be better written.
Doc bugs aren't critical.
The class overload page seems to be improved now, but the table on the structs pages lists "assign overload" rather than the better-describing "identity assign overload". https://github.com/D-Programming-Language/dlang.org/pull/562
Commits pushed to master at https://github.com/D-Programming-Language/dlang.org https://github.com/D-Programming-Language/dlang.org/commit/fee0b277069a2c0bcf5fc0b3f3370197e13a6163 Fix Issue 7075 - Use better wording for identity assignment overload. https://github.com/D-Programming-Language/dlang.org/commit/beece10c7eedd0e0f7416b104cc6ab8889e60792 Merge pull request #562 from AndrejMitrovic/Fix7075 [Trivial] Issue 7075 - Use better wording for identity assignment overload.