Getting 'this' of outer class?

David Medlock noone at nowhere.com
Mon Feb 20 05:59:48 PST 2006


Nick wrote:
> I'm sort of new to the inner class concept. I know the inner class has access to
> the outer class through a 'hidden' this reference, but how do I access this
> reference directly? Say I have the following:
> 
> # class A
> # {
> #    class B
> #    {
> #        B getB() { return this; } // Ok
> #        A getA() { return ???; } // How do I do this?
> #    }
> # }
> 
> Right now I'm stuck with adding a private getThis() member to A...
> 
> Nick
> 
> 
Which reference do you want?
Any number of A objects can create any B objects, unless A is a 
singleton what object would you be calling getThis() from??

How about:

class B {
  A parent;
  this( A parent ) { this.parent = parent; }
  ...
}

-DavidM



More information about the Digitalmars-d-learn mailing list