Sorry about the silly code, but I just tried this:

```
$ cat shared_aa.d
import std;

synchronized class shared_AA_class {
 private:
  int[int] aa;
  alias aa this;

 public:
  void print() {
          writeln(&aa, aa);
  }
}

struct shared_AA {
shared_AA_class saa = new shared_AA_class(); // by this syntax `saa` is still instance variable?
  alias saa this;
}

class Foo {
        shared shared_AA x;
        shared shared_AA y;

        this() {
                x[1] = 1;  // only modified `x`, not `y`
        }
}

void main() {
        Foo foo = new Foo();
        foo.x.print();
        foo.y.print();
        writeln(&(foo.x.saa));
        writeln(&(foo.y.saa));
}
```

```
$ dmd ./shared_aa
$ ./shared_aa
63B699474020[1:1]
63B699474020[1:1]
76CDDB518010
76CDDB518018
```

```
$ ldc2 shared_aa.d
$ ./shared_aa
558A95DF90C0[1:1]
558A95DF90C0[1:1]
743BE2B00010
743BE2B00018
```

Why `foo.x.saa.aa` and `foo.y.saa.aa` is the same? (and of course print out the same contents).

`shared_AA.saa` should still be instance variable, not class variable, right?

Thanks.

  • 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