Nested sibling classes

Salih Dincer salihdb at hotmail.com
Thu Jan 12 17:41:39 UTC 2023


On Thursday, 12 January 2023 at 17:05:04 UTC, seany wrote:

> How can I make it, that classes b and c can access each other, 
> and create instances of each other freely? Thank you.

Ignoring the typos you could try auto and static:

```d
class a
{ //outer

   static class b
   { // inner 1

     c C;
     this()
     {
       this.C = new c;
       //writeln(this.C.i);
     }
   }

   static class c
   { // inner 2
     int i = 10;
   }
}

int main ()
{
   int[21][1] test;
   test[0][20] = 19;

   assert(test[0][20] == 19);

   auto B = new a.b;
   auto C = new a.c;

   assert(B.C.i == 10);
   assert(C.i == 10);

   return 0;
  }
```
SDB at 79



More information about the Digitalmars-d-learn mailing list