www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - inner class how to explicityly access "outter this" pointer?

reply d d.com writes:
For non-static inner class, it contains a hidden "this" pointer to the outter,
how can I expplicitly access it?  Thanks.

e.g.

void globalFunc(Outter o) {
o.blah ...; 
}

class Outter {

class Inner {

void foo() {
globalFunc(???)  // how to explicityly access "outter this" pointer
}

}

}
Jul 31 2005
next sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
<d d.com> wrote in message news:dcjik7$u6t$1 digitaldaemon.com...
 For non-static inner class, it contains a hidden "this" pointer to the 
 outter,
 how can I expplicitly access it?  Thanks.

You can't, currently. This is something I also asked for a week or two ago.
Jul 31 2005
prev sibling parent reply Vathix <chris dprogramming.com> writes:
On Sun, 31 Jul 2005 18:16:39 -0400, <d d.com> wrote:

 For non-static inner class, it contains a hidden "this" pointer to the  
 outter,
 how can I expplicitly access it?  Thanks.

 e.g.

 void globalFunc(Outter o) {
 o.blah ...;
 }

 class Outter {

 class Inner {

 void foo() {
 globalFunc(???)  // how to explicityly access "outter this" pointer
 }

 }

 }

void globalFunc(Outer o) { } class Outer { final Outer outer() { return this; } class Inner { void foo() { globalFunc(outer); } } }
Jul 31 2005
parent reply Shammah Chancellor <Shammah_member pathlink.com> writes:
In article <op.suszt8qol2lsvj esi>, Vathix says...
On Sun, 31 Jul 2005 18:16:39 -0400, <d d.com> wrote:

 For non-static inner class, it contains a hidden "this" pointer to the  
 outter,
 how can I expplicitly access it?  Thanks.

 e.g.

 void globalFunc(Outter o) {
 o.blah ...;
 }

 class Outter {

 class Inner {

 void foo() {
 globalFunc(???)  // how to explicityly access "outter this" pointer
 }

 }

 }

void globalFunc(Outer o) { } class Outer { final Outer outer() { return this; } class Inner { void foo() { globalFunc(outer); } } }

The attributes documentation lists final, but does not say what it does. What does it do? -Sha
Jul 31 2005
parent Vathix <chris dprogramming.com> writes:
 The attributes documentation lists final, but does not say what it  
 does.  What
 does it do?

It's not required here. It just means the function can't be overridden and doesn't need to be virtual unless it's overriding something. Non-virtual has a bit (a lot?) of a performance gain. It's probably better to not use final in this case since you might want to override it in a derived class with a covariant (the derived type) return type. But sometimes I'll choose final if I don't expect to derive from the class, like if it's a private class.
Jul 31 2005