www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Ability to access the "outer this" pointer for nested classes planned?

reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
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.. 
Jul 13 2005
next sibling parent reply Dejan Lekic <leka entropy.tmok.com> writes:
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
  
Jul 14 2005
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"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.
Jul 14 2005
prev sibling next sibling parent Ulrik Mikaelsson <rawler rsn.bth.se> writes:
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..

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
Jul 20 2005
prev sibling next sibling parent Carlos Santander <csantander619 gmail.com> writes:
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
Jul 20 2005
prev sibling parent reply Ulrik Mikaelsson <rawler rsn.bth.se> writes:
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8Bit

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..

Jul 21 2005
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"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.
Jul 21 2005