Potential strategy for avoiding problems with copy of a struct (maybe??)

Ali Çehreli acehreli at yahoo.com
Sun Aug 22 14:35:48 UTC 2021


On 8/22/21 6:03 AM, james.p.leblanc wrote:

 >      struct Foo {
 >          int a, b, c;
 >          Foo* myadd;
 >
 >          this(int a, int b, int c) {
 >              this.a = a;
 >              this.b = b;
 >              this.c = c;
 >              this.myadd = &this;

As Matthias Lang mentioned, keeping a reference to itself makes a struct 
object illegal in D. D sees structs as value types: It is supposed that 
any copy can be used in place of another copy.

Ali



More information about the Digitalmars-d-learn mailing list