On Sunday, 22 August 2021 at 14:35:48 UTC, Ali Çehreli wrote:
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

Ali,

You highlight am important point that I have not been completely aware of.

Indeed, I did have a few "warning bells" going off in my brain when I began typing "this.myadd = &this;" into my program ... but, it compiled, so I
continued (into the potential quicksand, admittedly!)

So, thanks for illuminating this issue for me.

Also, the "postblit" hint recently posted in this thread, may allow me
to procede along a safer path.

Kind Regards,
James

Reply via email to