digitalmars.D.learn - Getting 'this' of outer class?
- Nick (13/13) Feb 19 2006 I'm sort of new to the inner class concept. I know the inner class has a...
- Jarrett Billingsley (8/22) Feb 19 2006 I don't think you can, not in the current implementation of inner classe...
- David Medlock (11/29) Feb 20 2006 Which reference do you want?
- David Mac (10/10) Sep 16 2006 To get the object reference of an outer class from an inner class:
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: Right now I'm stuck with adding a private getThis() member to A... Nick
Feb 19 2006
"Nick" <Nick_member pathlink.com> wrote in message news:dta0ca$2d3p$1 digitaldaemon.com...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: Right now I'm stuck with adding a private getThis() member to A...I don't think you can, not in the current implementation of inner classes, at least. There's probably a way to hack the inner class reference to get at the outer class reference, but it's probably not recommended ;) I agree that it'd be very nice to have. It's kind of like not being able to get the context pointer of delegates (which, according to Walter, are similar to how inner classes are implemented).
Feb 19 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: Right now I'm stuck with adding a private getThis() member to A... NickWhich 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
Feb 20 2006
To get the object reference of an outer class from an inner class: class A { class B { B getB {return this;} A getA {return A.this;} //=======// } }
Sep 16 2006