D - Inner Classes
- Rupert Millard (8/8) Aug 05 2003 Hi all!
- Walter (6/12) Aug 05 2003 way
- Rupert Millard (38/52) Aug 06 2003 Walter,
- Gennadi Pais (14/68) Aug 06 2003 Hi Rupert,
- Rupert Millard (27/112) Aug 06 2003 Gennadi,
- Gennadi Pais (8/127) Aug 06 2003 Rupert,
- Rupert Millard (20/156) Aug 06 2003 Gennadi,
- BenjiSmith (6/6) Aug 06 2003 As a former Java guy, I would personally RATHER have inner classes than ...
- Sean L. Palmer (8/14) Aug 06 2003 I've so often wished I could do that.
- Matthew Wilson (9/25) Aug 06 2003 Can we not have both?
- Mike Wynn (36/49) Aug 07 2003 I though we'd been through this b4, and Walter was totally against inner
Hi all! Does D sport inner classes / structs in any form? For some reason, I assumed it did and have got into some trouble! Either way I have at least one bug to report. If it is intended to have some support for these could someone explain what ways members of the outer class can be accessed? From, Rupert
Aug 05 2003
"Rupert Millard" <rupertamillard hotmail.dot.com> wrote in message news:bgnto9$qnv$2 digitaldaemon.com...Hi all! Does D sport inner classes / structs in any form? For some reason, I assumed it did and have got into some trouble! EitherwayI have at least one bug to report. If it is intended to have some support for these could someone explain what ways members of the outer class canbeaccessed?D supports nested classes, where the scopes are nested. It does not support java-style 'inner' classes. If you've found a bug, please post it here!
Aug 05 2003
Walter, I doubt this code should be allowed to compile as a struct is nested within a class, however it does compile and it produces this output on my machine when executed: in main(): x: 69 in B.displayX(): x: 4202672 I believe this behaviour is a bug. As I was not able to find any help in the manual, could you explain exactly what kind of nesting is allowed and what it permits you to do? Specifically what does nested scopes mean? Also, I understand that there is some ambiguity in the term 'inner classes' in JAVA. Could somebody clarify exactly what it means? Please excuse my ignorance, I am an entirely self-taught programmer doing it as a hobby. Thanks, From, Rupert "Walter" <walter digitalmars.com> wrote in message news:bgorth$1pmc$2 digitaldaemon.com..."Rupert Millard" <rupertamillard hotmail.dot.com> wrote in message news:bgnto9$qnv$2 digitaldaemon.com...supportHi all! Does D sport inner classes / structs in any form? For some reason, I assumed it did and have got into some trouble! EitherwayI have at least one bug to report. If it is intended to have somesupportfor these could someone explain what ways members of the outer class canbeaccessed?D supports nested classes, where the scopes are nested. It does notjava-style 'inner' classes. If you've found a bug, please post it here!begin 666 bug.d M+R\ 0E5'. T*+R\ ;F5S=&5D(&-L87-S97, 9&]N)W0 8V]R<F5C=&QY(&%C M(' R*0T*"7L-" D)>#UX M.PT*"0D-" D)8BYD:7-P;&%Y6" I.PT*"7T-"GT-" T*:6YT(&UA:6X *&-H M9B B:6X ;6%I;B I.EQN( T*"2 (" (" B>#H )74 7&Y<;B(L(&$N>"D[ ` end
Aug 06 2003
Hi Rupert, for the Java-style inner class explanation you can read the next link: http://java.sun.com/docs/books/tutorial/java/javaOO/innerclasses.html Hope you'll find that is brief and clear. About the "bug" you arose I think that is not a bug at all. Pay attention to explanation about nested function that described either on the page 100 of the D spec in pdf pormat or go to the http://www.digitalmars.com/d/function.html When you declare (and define) a nested class in another one you just declare the scope of that class, not a variable or some kind of instance that is connected to concrete instance ot outer class. So an inner class can't receive a value of non-static member of outer one, have no access to its frame. Hope I've succeeded to explain the "bug" behavior. Thanks! In article <bgqm0m$g2h$1 digitaldaemon.com>, Rupert Millard says...Walter, I doubt this code should be allowed to compile as a struct is nested within a class, however it does compile and it produces this output on my machine when executed: in main(): x: 69 in B.displayX(): x: 4202672 I believe this behaviour is a bug. As I was not able to find any help in the manual, could you explain exactly what kind of nesting is allowed and what it permits you to do? Specifically what does nested scopes mean? Also, I understand that there is some ambiguity in the term 'inner classes' in JAVA. Could somebody clarify exactly what it means? Please excuse my ignorance, I am an entirely self-taught programmer doing it as a hobby. Thanks, From, Rupert "Walter" <walter digitalmars.com> wrote in message news:bgorth$1pmc$2 digitaldaemon.com..."Rupert Millard" <rupertamillard hotmail.dot.com> wrote in message news:bgnto9$qnv$2 digitaldaemon.com...supportHi all! Does D sport inner classes / structs in any form? For some reason, I assumed it did and have got into some trouble! EitherwayI have at least one bug to report. If it is intended to have somesupportfor these could someone explain what ways members of the outer class canbeaccessed?D supports nested classes, where the scopes are nested. It does notjava-style 'inner' classes. If you've found a bug, please post it here!begin 666 bug.d M+R\ 0E5'. T*+R\ ;F5S=&5D(&-L87-S97, 9&]N)W0 8V]R<F5C=&QY(&%C M(' R*0T*"7L-" D)>#UX M.PT*"0D-" D)8BYD:7-P;&%Y6" I.PT*"7T-"GT-" T*:6YT(&UA:6X *&-H M9B B:6X ;6%I;B I.EQN( T*"2 (" (" B>#H )74 7&Y<;B(L(&$N>"D[ ` end
Aug 06 2003
Gennadi, Thanks for the link. I don't see the relevance of nested functions to the problem in question, however the manual says "Nested functions have access to the variables and other symbols defined by the lexically enclosing function." If one were to infer anything about nested classes from this, wouldn't it be that a nested class could access the members of the enclosing class? If what you go on to say is the case then shouldn't the compiler generate an error (as it would do if B were a class instead of a struct) rather than compiling the code? From, Rupert "Gennadi Pais" <Gennadi_member pathlink.com> wrote in message news:bgqq03$jgj$1 digitaldaemon.com...Hi Rupert, for the Java-style inner class explanation you can read the next link: http://java.sun.com/docs/books/tutorial/java/javaOO/innerclasses.html Hope you'll find that is brief and clear. About the "bug" you arose I think that is not a bug at all. Pay attentiontoexplanation about nested function that described either on the page 100 ofthe Dspec in pdf pormat or go to the http://www.digitalmars.com/d/function.html When you declare (and define) a nested class in another one you justdeclare thescope of that class, not a variable or some kind of instance that isconnectedto concrete instance ot outer class. So an inner class can't receive avalue ofnon-static member of outer one, have no access to its frame. Hope I've succeeded to explain the "bug" behavior. Thanks! In article <bgqm0m$g2h$1 digitaldaemon.com>, Rupert Millard says...withinWalter, I doubt this code should be allowed to compile as a struct is nestedmachinea class, however it does compile and it produces this output on myexactlywhen executed: in main(): x: 69 in B.displayX(): x: 4202672 I believe this behaviour is a bug. As I was not able to find any help in the manual, could you explainSpecificallywhat kind of nesting is allowed and what it permits you to do?classes'what does nested scopes mean? Also, I understand that there is some ambiguity in the term 'inneritin JAVA. Could somebody clarify exactly what it means? Please excuse my ignorance, I am an entirely self-taught programmer doingEitheras a hobby. Thanks, From, Rupert "Walter" <walter digitalmars.com> wrote in message news:bgorth$1pmc$2 digitaldaemon.com..."Rupert Millard" <rupertamillard hotmail.dot.com> wrote in message news:bgnto9$qnv$2 digitaldaemon.com...Hi all! Does D sport inner classes / structs in any form? For some reason, I assumed it did and have got into some trouble!canwaysupportI have at least one bug to report. If it is intended to have somefor these could someone explain what ways members of the outer classbesupportaccessed?D supports nested classes, where the scopes are nested. It does notjava-style 'inner' classes. If you've found a bug, please post it here!begin 666 bug.d M+R\ 0E5'. T*+R\ ;F5S=&5D(&-L87-S97, 9&]N)W0 8V]R<F5C=&QY(&%C M(' R*0T*"7L-" D)>#UX M.PT*"0D-" D)8BYD:7-P;&%Y6" I.PT*"7T-"GT-" T*:6YT(&UA:6X *&-H M9B B:6X ;6%I;B I.EQN( T*"2 (" (" B>#H )74 7&Y<;B(L(&$N>"D[ ` end
Aug 06 2003
Rupert, You could see the example of variable access from inner class in function (not in outer class) in the D spec: "Member functions of nested classes and structs do not have access to the stack variables of the enclosing function, but do have access to the other symbols". So I think that is the same logical decision. In the question of compilation error I agree with. Thanks! In article <bgqsqc$lvm$1 digitaldaemon.com>, Rupert Millard says...Gennadi, Thanks for the link. I don't see the relevance of nested functions to the problem in question, however the manual says "Nested functions have access to the variables and other symbols defined by the lexically enclosing function." If one were to infer anything about nested classes from this, wouldn't it be that a nested class could access the members of the enclosing class? If what you go on to say is the case then shouldn't the compiler generate an error (as it would do if B were a class instead of a struct) rather than compiling the code? From, Rupert "Gennadi Pais" <Gennadi_member pathlink.com> wrote in message news:bgqq03$jgj$1 digitaldaemon.com...Hi Rupert, for the Java-style inner class explanation you can read the next link: http://java.sun.com/docs/books/tutorial/java/javaOO/innerclasses.html Hope you'll find that is brief and clear. About the "bug" you arose I think that is not a bug at all. Pay attentiontoexplanation about nested function that described either on the page 100 ofthe Dspec in pdf pormat or go to the http://www.digitalmars.com/d/function.html When you declare (and define) a nested class in another one you justdeclare thescope of that class, not a variable or some kind of instance that isconnectedto concrete instance ot outer class. So an inner class can't receive avalue ofnon-static member of outer one, have no access to its frame. Hope I've succeeded to explain the "bug" behavior. Thanks! In article <bgqm0m$g2h$1 digitaldaemon.com>, Rupert Millard says...withinWalter, I doubt this code should be allowed to compile as a struct is nestedmachinea class, however it does compile and it produces this output on myexactlywhen executed: in main(): x: 69 in B.displayX(): x: 4202672 I believe this behaviour is a bug. As I was not able to find any help in the manual, could you explainSpecificallywhat kind of nesting is allowed and what it permits you to do?classes'what does nested scopes mean? Also, I understand that there is some ambiguity in the term 'inneritin JAVA. Could somebody clarify exactly what it means? Please excuse my ignorance, I am an entirely self-taught programmer doingEitheras a hobby. Thanks, From, Rupert "Walter" <walter digitalmars.com> wrote in message news:bgorth$1pmc$2 digitaldaemon.com..."Rupert Millard" <rupertamillard hotmail.dot.com> wrote in message news:bgnto9$qnv$2 digitaldaemon.com...Hi all! Does D sport inner classes / structs in any form? For some reason, I assumed it did and have got into some trouble!canwaysupportI have at least one bug to report. If it is intended to have somefor these could someone explain what ways members of the outer classbesupportaccessed?D supports nested classes, where the scopes are nested. It does notjava-style 'inner' classes. If you've found a bug, please post it here!begin 666 bug.d M+R\ 0E5'. T*+R\ ;F5S=&5D(&-L87-S97, 9&]N)W0 8V]R<F5C=&QY(&%C M(' R*0T*"7L-" D)>#UX M.PT*"0D-" D)8BYD:7-P;&%Y6" I.PT*"7T-"GT-" T*:6YT(&UA:6X *&-H M9B B:6X ;6%I;B I.EQN( T*"2 (" (" B>#H )74 7&Y<;B(L(&$N>"D[ ` end
Aug 06 2003
Gennadi, Well spotted! Thanks very much for all your help. From, Rupert "Gennadi Pais" <Gennadi_member pathlink.com> wrote in message news:bgqumc$nop$1 digitaldaemon.com...Rupert, You could see the example of variable access from inner class in function(notin outer class) in the D spec: "Member functions of nested classes andstructsdo not have access to the stack variables of the enclosing function, butdo haveaccess to the other symbols". So I think that is the same logicaldecision.In the question of compilation error I agree with. Thanks! In article <bgqsqc$lvm$1 digitaldaemon.com>, Rupert Millard says...andGennadi, Thanks for the link. I don't see the relevance of nested functions to the problem in question, however the manual says "Nested functions have access to the variablestoother symbols defined by the lexically enclosing function." If one werenestedinfer anything about nested classes from this, wouldn't it be that aanclass could access the members of the enclosing class? If what you go on to say is the case then shouldn't the compiler generateattentionerror (as it would do if B were a class instead of a struct) rather than compiling the code? From, Rupert "Gennadi Pais" <Gennadi_member pathlink.com> wrote in message news:bgqq03$jgj$1 digitaldaemon.com...Hi Rupert, for the Java-style inner class explanation you can read the next link: http://java.sun.com/docs/books/tutorial/java/javaOO/innerclasses.html Hope you'll find that is brief and clear. About the "bug" you arose I think that is not a bug at all. Payoftoexplanation about nested function that described either on the page 100http://www.digitalmars.com/d/function.htmlthe Dspec in pdf pormat or go to thedoingWhen you declare (and define) a nested class in another one you justdeclare thescope of that class, not a variable or some kind of instance that isconnectedto concrete instance ot outer class. So an inner class can't receive avalue ofnon-static member of outer one, have no access to its frame. Hope I've succeeded to explain the "bug" behavior. Thanks! In article <bgqm0m$g2h$1 digitaldaemon.com>, Rupert Millard says...withinWalter, I doubt this code should be allowed to compile as a struct is nestedmachinea class, however it does compile and it produces this output on myexactlywhen executed: in main(): x: 69 in B.displayX(): x: 4202672 I believe this behaviour is a bug. As I was not able to find any help in the manual, could you explainSpecificallywhat kind of nesting is allowed and what it permits you to do?classes'what does nested scopes mean? Also, I understand that there is some ambiguity in the term 'innerin JAVA. Could somebody clarify exactly what it means? Please excuse my ignorance, I am an entirely self-taught programmerclassitEitheras a hobby. Thanks, From, Rupert "Walter" <walter digitalmars.com> wrote in message news:bgorth$1pmc$2 digitaldaemon.com..."Rupert Millard" <rupertamillard hotmail.dot.com> wrote in message news:bgnto9$qnv$2 digitaldaemon.com...Hi all! Does D sport inner classes / structs in any form? For some reason, I assumed it did and have got into some trouble!waysupportI have at least one bug to report. If it is intended to have somefor these could someone explain what ways members of the outerhere!canbesupportaccessed?D supports nested classes, where the scopes are nested. It does notjava-style 'inner' classes. If you've found a bug, please post itbegin 666 bug.d M+R\ 0E5'. T*+R\ ;F5S=&5D(&-L87-S97, 9&]N)W0 8V]R<F5C=&QY(&%C M(' R*0T*"7L-" D)>#UX M.PT*"0D-" D)8BYD:7-P;&%Y6" I.PT*"7T-"GT-" T*:6YT(&UA:6X *&-H M9B B:6X ;6%I;B I.EQN( T*"2 (" (" B>#H )74 7&Y<;B(L(&$N>"D[ ` end
Aug 06 2003
As a former Java guy, I would personally RATHER have inner classes than nested classes. As far as I can tell, nested classes only limit the SCOPE of the class, which can occasionally be somewhat useful. But inner classes allow the inner class to talk to the outer class, which can OFTEN be REALLY useful. I'd love to see inner classes in D. --Benji Smith
Aug 06 2003
I've so often wished I could do that. I'd like to see some kind of inner class support as well. Sean "BenjiSmith" <BenjiSmith_member pathlink.com> wrote in message news:bgr1m8$qmc$1 digitaldaemon.com...As a former Java guy, I would personally RATHER have inner classes thannestedclasses. As far as I can tell, nested classes only limit the SCOPE of theclass,which can occasionally be somewhat useful. But inner classes allow theinnerclass to talk to the outer class, which can OFTEN be REALLY useful. I'd love to see inner classes in D. --Benji Smith
Aug 06 2003
Can we not have both? I've found nested classes very useful in C++, essential in many ways to enforce design decisions and control users of one's classes. I've found inner classes very useful in Java (along with those groovy anonymous gizmos) Let's have both in D! "Sean L. Palmer" <palmer.sean verizon.net> wrote in message news:bgrcff$1563$1 digitaldaemon.com...I've so often wished I could do that. I'd like to see some kind of inner class support as well. Sean "BenjiSmith" <BenjiSmith_member pathlink.com> wrote in message news:bgr1m8$qmc$1 digitaldaemon.com...theAs a former Java guy, I would personally RATHER have inner classes thannestedclasses. As far as I can tell, nested classes only limit the SCOPE ofclass,which can occasionally be somewhat useful. But inner classes allow theinnerclass to talk to the outer class, which can OFTEN be REALLY useful. I'd love to see inner classes in D. --Benji Smith
Aug 06 2003
"Matthew Wilson" <matthew stlsoft.org> wrote in message news:bgs4et$1s2p$1 digitaldaemon.com...Can we not have both? I've found nested classes very useful in C++, essential in many ways to enforce design decisions and control users of one's classes. I've found inner classes very useful in Java (along with those groovy anonymous gizmos) Let's have both in D! "Sean L. Palmer" <palmer.sean verizon.net> wrote in message news:bgrcff$1563$1 digitaldaemon.com...I though we'd been through this b4, and Walter was totally against inner classes, becuase inner functions as delgates can (in many places) replace them. however if we're back on that, I too vote for inner classes akin to Java, they are more robust than inner functions as delegates (and infact you could make a delegate of a fuction of an anon innerclass that was a shallow copy of the inner functions stack frame, thus full closures). I would like to see one addition to inner classes, that of allowing an inner class to be subclassed without having to subclass the outer class. as in class Base { inner class Item { // I've used inner here as in Java it would be class, but in D class means Java static class ... } } in Java to have a subclass of Base.Item you need to do class Derived : Base { inner class MyItem : Base.Item { } } because MyItem needs an instance of Base to be connected to; I would like to see class MyItem : Item.Base { // assumes that MyItem is connected to a Base } to create an instance of a MyClass use something like Base b = new Base(); MyItem ii = b.new MyItem(); or even class Derived : Base { } Derived d = new Derived(); MyItem ii = d.new MyItem();I've so often wished I could do that. I'd like to see some kind of inner class support as well. Sean
Aug 07 2003