Re: opAssign for most struct assignment calls not executed

2017-11-23 Thread Timoses via Digitalmars-d-learn
On Thursday, 23 November 2017 at 15:45:17 UTC, Rene Zwanenburg wrote: On Thursday, 23 November 2017 at 15:26:03 UTC, Timoses wrote: A aaa = a; That's initialization, not assignment, which is subtly different. It will call the postblit on aaa instead of opAssign. A postblit can be

Re: opAssign for most struct assignment calls not executed

2017-11-23 Thread Rene Zwanenburg via Digitalmars-d-learn
On Thursday, 23 November 2017 at 15:26:03 UTC, Timoses wrote: A aaa = a; That's initialization, not assignment, which is subtly different. It will call the postblit on aaa instead of opAssign. A postblit can be defined this way: this(this) { } There is no way to access the original a

Re: opAssign for most struct assignment calls not executed

2017-11-23 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 23 November 2017 at 15:26:03 UTC, Timoses wrote: A member; this(A a) { this.member = a; // specifically aiming towards this assignment... That's not assignment, that's construction. opAssign is only called when you assign over a struct object that already

opAssign for most struct assignment calls not executed

2017-11-23 Thread Timoses via Digitalmars-d-learn
What am I missing? import std.stdio; struct A { int value; A opAssign(A a) { writeln(" Assigning"); return this; // I know this makes little sense, just for illustration } } class B { A member; this(A a) { this.member = a; //