digitalmars.D.learn - Anonymous nested classes
- John C (29/29) Jun 09 2005 I'm trying out the new anonymous nested classes, and can't figure out wh...
- Chris Sauls (7/12) Jun 09 2005 I have no clue... Probably something odd about the way anonymous classes...
- John C (7/20) Jun 09 2005 Doesn't work, sadly.
- Walter (1/1) Jun 10 2005 It's a compiler bug. I need to get it fixed.
I'm trying out the new anonymous nested classes, and can't figure out why this won't compile: public interface Iterator { public bool moveNext(); public Object current(); } public class Stack { public Iterator interator() { return new class Iterator { public this() { currentIndex_ = items_.length - 1; // error here: this for items_ needs to be type Stack not type void* } public bool moveNext() { return currentIndex_ >= 0; } public Object current() { return items_[currentIndex_]; // error here: this for items_ needs to be type Stack not type void* } private int currentIndex_; }; } private Object[] items_; } The anonymous class (which inherits from Iterator) should have access to its enclosing class's members. Or have I gone bonkers?
Jun 09 2005
return new class Iterator {I think this is supposed to be something like:public this() { currentIndex_ = items_.length - 1; // error here: this for items_ needs to be type Stack not type void* }I have no clue... Probably something odd about the way anonymous classes are implemented. Might try using something like 'Stack.items_' but I would expect that to be treated as a static referance. Maybe 'this.outer.items_' or something therelike will become available. -- Chris Sauls
Jun 09 2005
"Chris Sauls" <ibisbasenji gmail.com> wrote in message news:d8a67b$264i$1 digitaldaemon.com...Doesn't work, sadly. Since the point was to ease translation of Java code, I thought returning anonymous classes would be possible, as it is in Java. Looks like it's not. Has anyone else sussed this out yet? Perhaps an example in the spec is in order.return new class Iterator {I think this is supposed to be something like:public this() { currentIndex_ = items_.length - 1; // error here: this for items_ needs to be type Stack not type void* }I have no clue... Probably something odd about the way anonymous classes are implemented. Might try using something like 'Stack.items_' but I would expect that to be treated as a static referance. Maybe 'this.outer.items_' or something therelike will become available. -- Chris Sauls
Jun 09 2005
It's a compiler bug. I need to get it fixed.
Jun 10 2005
In article <d8d2gp$20ea$1 digitaldaemon.com>, Walter says...It's a compiler bug. I need to get it fixed.Sorry, I don't see how DMD 0.127 really fixes that, it still errs (now complaining, that items_ is not accessible). How to make that code compilable (other than making items_ public). Sorry if this is a dumb question, i'm a D newbie ;) Kind regards, Stefan
Jun 23 2005
In article <d8d2gp$20ea$1 digitaldaemon.com>, Walter says...It's a compiler bug. I need to get it fixed.Sorry, I don't see how DMD 0.127 really fixes that, it still errs (now complaining, that items_ is not accessible). How to make that code compilable (other than making items_ public). Sorry if this is a dumb question, i'm a D newbie ;) Kind regards, Stefan
Jun 23 2005
In article <d9fce8$gcs$1 digitaldaemon.com>, Stefan says...In article <d8d2gp$20ea$1 digitaldaemon.com>, Walter says...Sorry for double posting. Seem to have hitten the post button twice :-(It's a compiler bug. I need to get it fixed.Sorry, I don't see how DMD 0.127 really fixes that, it still errs (now complaining, that items_ is not accessible). How to make that code compilable (other than making items_ public). Sorry if this is a dumb question, i'm a D newbie ;) Kind regards, Stefan
Jun 23 2005