Can I call the default opAssign after overloading opAssign?
Rob T
rob at ucora.com
Fri Nov 23 14:31:45 PST 2012
On Monday, 19 November 2012 at 12:10:32 UTC, Dan wrote:
> [...]
> provide it - you do not need an opAssign at all, as your
> postblit will be called. I think this is a step up over C++.
>
> The example below prints:
> ----------------------------------------------
> Begin assign
> postblit A
> End assign
> ----------------------------------------------
>
> import std.stdio;
> import std.traits;
>
> struct A {
> this(this) { c = c.dup; writeln("postblit A"); }
> char[] c;
>
> }
> struct B { A a; }
> struct C { B b; }
> struct D { C c; }
>
> void main() {
> D d1, d2;
> d1.c.b.a.c = ['a','b','c'];
> writeln("Begin assign");
> d2 = d1;
> writeln("End assign");
> }
That's VERY interesting indeed and originally I had no idea it
would do this without a custom opAssign at each level.
This kind of behavior *really* needs to be documented in precise
detail, it's rather critical to know.
--rt
More information about the Digitalmars-d-learn
mailing list