Thread overview
Ability to access the "outer this" pointer for nested classes planned?
Jul 14, 2005
Dejan Lekic
Jul 20, 2005
Ulrik Mikaelsson
Jul 21, 2005
Carlos Santander
Jul 21, 2005
Ulrik Mikaelsson
July 14, 2005
Sorry, but I don't know if this is implemented in Java, which D's nested classes are based upon.  But what I'm wondering if there is any plans for an "outer" member available for nested classes.  It seems a bit strange that nested classes are implicitly associated with a certain instance of their outer class, but we can't access the pointer to the outer class.  We must pass that as a parameter to the inner class's ctor.  I don't know how an .outer member would behave for classes nested in functions, however..


July 14, 2005
Jarrett, there are other much older languages that has nested classes... Java "borrowed" ideas from them, as well as D.

Kind regards

Dejan

-- 
...........
Dejan Lekic
  http://dejan.lekic.org

July 14, 2005
"Dejan Lekic" <leka@entropy.tmok.com> wrote in message news:db5i0h$2hfm$1@digitaldaemon.com...
> Jarrett, there are other much older languages that has nested classes... Java "borrowed" ideas from them, as well as D.

Oh well.  That's OK by me.


July 20, 2005
Jarrett Billingsley wrote:

> Sorry, but I don't know if this is implemented in Java, which D's nested
> classes are based upon.  But what I'm wondering if there is any plans for
> an
> "outer" member available for nested classes.  It seems a bit strange that
> nested classes are implicitly associated with a certain instance of their
> outer class, but we can't access the pointer to the outer class.  We must
> pass that as a parameter to the inner class's ctor.  I don't know how an
> .outer member would behave for classes nested in functions, however..
Actually, I would like to ask the same question?

The main reason that I see for nested classes is when there is a very tight coupling between the classes, such as for instance an exception generated in a class.

It seems illogical to hide this coupling when it's already there.

Regards
/ Ulrik
July 21, 2005
Jarrett Billingsley escribió:
> Sorry, but I don't know if this is implemented in Java, which D's nested classes are based upon.  But what I'm wondering if there is any plans for an "outer" member available for nested classes.  It seems a bit strange that nested classes are implicitly associated with a certain instance of their outer class, but we can't access the pointer to the outer class.  We must pass that as a parameter to the inner class's ctor.  I don't know how an ..outer member would behave for classes nested in functions, however.. 
> 
> 

I think there's a way to access the outer class, so probably this should've been in D.learn. The problem is that I also don't know how to do that. Anybody cares to answer?

-- 
Carlos Santander Bernal
July 21, 2005
On a possibly related topic:
On compilation, the attached program causes an error:

[rawler@gunther ~]$ dmd nesting.d
nesting.d(19): no 'this' for nested class MyError

How shall I interpret this? Is it not possible to declare an inner class to be an Exception? Or am I doing something wrong?

Regards
/ Ulrik

Jarrett Billingsley wrote:

> Sorry, but I don't know if this is implemented in Java, which D's nested
> classes are based upon.  But what I'm wondering if there is any plans for
> an
> "outer" member available for nested classes.  It seems a bit strange that
> nested classes are implicitly associated with a certain instance of their
> outer class, but we can't access the pointer to the outer class.  We must
> pass that as a parameter to the inner class's ctor.  I don't know how an
> .outer member would behave for classes nested in functions, however..


July 21, 2005
"Ulrik Mikaelsson" <rawler@rsn.bth.se> wrote in message news:dbovkm$2qr8$1@digitaldaemon.com...
> On a possibly related topic:
> On compilation, the attached program causes an error:
>
> [rawler@gunther ~]$ dmd nesting.d
> nesting.d(19): no 'this' for nested class MyError
>
> How shall I interpret this? Is it not possible to declare an inner class
> to
> be an Exception? Or am I doing something wrong?

Any function that creates a MyError must be a non-static member function of A.  No other function may create a MyError.  That's the simplest explanation.