Lack of `outer` keyword makes inner class dup implossible

S. S._member at pathlink.com
Mon Jul 17 08:27:46 PDT 2006


In article <e9e8h8$1asn$1 at digitaldaemon.com>, Frits van Bommel says...
>
>S. Chancellor wrote:
>> Exactly.  Interestingly though I tried this:
>> 
>> class Board {
>>     Board outer;
>>     this() { outer = this; }
>>     class Cell {
>>         Cell dup() {
>>             return new outer.Cell;
>>         }
>>     }
>> 
>> and I get syntax errors.   This new expression stuff seems broken.
>
>First thing you'll want to do is close all your braces. You missed one :).
>
>The 'new' syntax is a bit weird for inner classes I think. This should work:
>
>class Board {
>     Board outer;
>     this() { outer = this; }
>     class Cell {
>         Cell dup() {
>             return outer.new Cell;
>         }
>     }
>}
>
>I agree that 'new outer.Cell' is a more intuitive syntax for this, but 
>that's just not the way it works...
>This is also the syntax for 'new'ing an inner class in Java, IIRC. I 
>remember tripping over the syntax a couple of times when I was using 
>Java. (I haven't needed inner classes in D yet[1])
>
>See also http://www.digitalmars.com/d/class.html (almost at the very 
>end, just above the heading "Anonymous Nested Classes")

I made some typo's -- that is not the verbatim code I was tring to compile.  I
had outer.new Cell and all my braces closed.  Did you try to compile yours?







More information about the Digitalmars-d mailing list