On 25/06/2024 2:16 PM, mw wrote:
struct shared_AA {
  shared_AA_class saa = new shared_AA_class();  // by this syntax `saa` is still instance variable?
   alias saa this;
}

When you specify an initializer like this, that instance of ``shared_AA_class`` gets put into the .init of ``shared_AA``.

It is shared between instances, even if its a field.

```d
import std.stdio;

struct Foo {
    ubyte value = 2;
}

void main() {
    writeln(cast(ubyte[])__traits(initSymbol, Foo)); // [2]
}
```
  • Why `foo.x.saa.a... mw via Digitalmars-d-learn
    • Re: Why `fo... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
      • Re: Why... mw via Digitalmars-d-learn
        • Re:... Kagamin via Digitalmars-d-learn
        • Re:... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
    • Re: Why `fo... Nick Treleaven via Digitalmars-d-learn

Reply via email to