Nested sibling classes

seany seany at uni-bonn.de
Thu Jan 12 17:46:45 UTC 2023


On Thursday, 12 January 2023 at 17:41:39 UTC, Salih Dincer wrote:
> 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

Hi

Moving the "new c" within the this() function indeed solved it. 
Thank you for pointing out the typos.

Please, can you explain what role "static" plays here? Thank you 
again


More information about the Digitalmars-d-learn mailing list