Please Consider the code:

        import std.stdio;

        class a {

        public:
             this(){}
            ~this(){}

            class b {

            public:
                    this.outer.c C = new this.outer.c();
                     this() {
                            writeln(this.C.i);
                    }
                    ~this() {}

            }

            class c {
            public:
                     this() {}
                    ~this() {}
                    int i = 10;
            }

        }


        int main () {

            int [int][int] test;

            test[0][20] = 19;
            writeln(Test[0][20]);


            a A = new A();
            a.b B = a.new a.b();
            return 0;
        }


Compiling with dmd tells me:
`test.d(12): Error: undefined identifier `` this.outer.c `` ` (i used two backticks, but i can't seem tobe escaping the backtick character correctly in this forum)

On fish shell we have:
❯ dmd --version
DMD64 D Compiler v2.101.2

Copyright (C) 1999-2022 by The D Language Foundation, All Rights Reserved written by Walter Bright


If i remove the "this.outer" and just write, c C = new c(); then i have:

`test.d(12): Error: cannot construct nested class ` c ` because no implicit ` this ` reference to outer class ` a ` is available`


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

Reply via email to