Struct inside a class: How to get outer?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sun Dec 3 07:38:47 UTC 2017


On Sunday, December 03, 2017 01:05:00 Nick Sabalausky  via Digitalmars-d-
learn wrote:
> Is this even possible? My attempts:
>
> class Outer {
>   struct Inner {
>       void foo() {
>           // Error: no property 'outer' for type 'Inner'
>           Outer o = this.outer;
>
>           // Error: cannot implicitly convert expression
>           // this of type Inner to testNested.Outer
>           Outer o = this;
>       }
>   }
> }

As I understand it, there is no outer for nested structs, only nested
classes. So, you'll either have to use a nested class or explicitly pass a
reference to the outer class to the nested struct.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list