digitalmars.D.learn - [Bug or feature] nested class inheritance
- David Ferenczi (24/24) Apr 15 2007 Compiling the code below gives an error message:
- Thomas Kuehne (15/36) Apr 15 2007 -----BEGIN PGP SIGNED MESSAGE-----
- Bradley Smith (18/60) Apr 15 2007 I don't understand this answer. If the classes are moved to the module
- janderson (16/83) Apr 16 2007 Looks like they both need to be in the same scope. Although I don't see...
- David Ferenczi (47/85) Apr 15 2007 Thank you very much for the quick answer.
- BCS (6/12) Apr 15 2007 [...]
- David Ferenczi (2/16) Apr 16 2007 Should we file a bug, or is there one already? (I haven't found)
- BCS (4/26) Apr 16 2007 I don't think that there is a bug filed. If you want to, go ahead and
- Bradley Smith (4/25) Apr 16 2007 Where is the spec is this behavior mentioned?
- BCS (2/6) Apr 16 2007 I can't seem to find it. Maybe I'm just rembering a comment from walter.
Compiling the code below gives an error message: ----------------8<--------------------------------- int main(char[][] args) { class A { protected: class AA {} } class B : A { protected: class BB : AA {} } return 0; } ----------------8<--------------------------------- test.d(15): class test.main.B.BB super class AA is nested within A, not B Is it the intended behaviour? Does it mean that nested classes wont get inherited, thus cannot be used in the subclass? Thanks in advance, regards, David
Apr 15 2007
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 David Ferenczi schrieb am 2007-04-15:Compiling the code below gives an error message: ----------------8<--------------------------------- int main(char[][] args) { class A { protected: class AA {} } class B : A { protected: class BB : AA {} } return 0; } ----------------8<--------------------------------- test.d(15): class test.main.B.BB super class AA is nested within A, not B Is it the intended behaviour?YesDoes it mean that nested classes wont get inherited, thus cannot be used in the subclass?No. The classes are defined inside a function and thus: Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFGIleHLK5blCcjpWoRAsB0AKCN+BAUHrAq+ad72ZRge8zjOFXr7gCgrHEZ fj21+kHJG+S+PePA05DG0dE= =4Cpp -----END PGP SIGNATURE-----
Apr 15 2007
Thomas Kuehne wrote:-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 David Ferenczi schrieb am 2007-04-15:I don't understand this answer. If the classes are moved to the module level, the same error results. Why? class A { protected: class AA {} } class B : A { protected: class BB : AA {} } int main(char[][] args) { return 0; } test.d(10): class test.B.BB super class AA is nested within A, not BCompiling the code below gives an error message: ----------------8<--------------------------------- int main(char[][] args) { class A { protected: class AA {} } class B : A { protected: class BB : AA {} } return 0; } ----------------8<--------------------------------- test.d(15): class test.main.B.BB super class AA is nested within A, not B Is it the intended behaviour?YesDoes it mean that nested classes wont get inherited, thus cannot be used in the subclass?No. The classes are defined inside a function and thus: Thomas
Apr 15 2007
Bradley Smith wrote:Thomas Kuehne wrote:Looks like they both need to be in the same scope. Although I don't see why this restriction couldn't be freed for these cases to work more like they do in C++. ie we still get an error message with: class A { public: class AA {} } class B : A { protected: class BB : A.AA {} } test.d(10): class test.B.BB super class AA is nested within A, not B -Joel-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 David Ferenczi schrieb am 2007-04-15:I don't understand this answer. If the classes are moved to the module level, the same error results. Why? class A { protected: class AA {} } class B : A { protected: class BB : AA {} } int main(char[][] args) { return 0; } test.d(10): class test.B.BB super class AA is nested within A, not BCompiling the code below gives an error message: ----------------8<--------------------------------- int main(char[][] args) { class A { protected: class AA {} } class B : A { protected: class BB : AA {} } return 0; } ----------------8<--------------------------------- test.d(15): class test.main.B.BB super class AA is nested within A, not B Is it the intended behaviour?YesDoes it mean that nested classes wont get inherited, thus cannot be used in the subclass?No. The classes are defined inside a function and thus: Thomas
Apr 16 2007
Thank you very much for the quick answer. Maybe I miss some important point, but I don't understand why the processing order explains the behaviour. In my original code the situation looks like this: a.d: ----------------8<--------------------------------- class A { protected: class AA {} } ----------------8<--------------------------------- b.d: ----------------8<--------------------------------- static private import a: A; class B : A { protected: class BB : AA {} } ----------------8<--------------------------------- What I would like to do is to nest AA class in A. Let another class B in another module inherit from A. Let B have a nested class BB, which inherits from AA. What should I do to achieve this? Or is it totally worng? If I put class AA outside A, everything works. a.d: ----------------8<--------------------------------- class A { } class AA { } ----------------8<--------------------------------- b.d: ----------------8<--------------------------------- static private import a: A, AA; class B : A { protected: class BB : AA {} } ----------------8<--------------------------------- Thank you very much for your help, DavidCompiling the code below gives an error message: ----------------8<--------------------------------- int main(char[][] args) { class A { protected: class AA {} } class B : A { protected: class BB : AA {} } return 0; } ----------------8<--------------------------------- test.d(15): class test.main.B.BB super class AA is nested within A, not B Is it the intended behaviour?YesDoes it mean that nested classes wont get inherited, thus cannot be used in the subclass?No. The classes are defined inside a function and thus: Thomas
Apr 15 2007
Reply to David,Thank you very much for the quick answer. Maybe I miss some important point, but I don't understand why the processing order explains the behaviour. In my original code the situation looks like this:[...] A nested class can only be derived from by another class nested inside the same class. As far as I am concerned, this is a design bug or mis-feature. I to have wanted to do exactly what you were trying to do. I could be wrong but I can't see any reason that it should be hard to implement.
Apr 15 2007
BCS wrote:Reply to David,Should we file a bug, or is there one already? (I haven't found)Thank you very much for the quick answer. Maybe I miss some important point, but I don't understand why the processing order explains the behaviour. In my original code the situation looks like this:[...] A nested class can only be derived from by another class nested inside the same class. As far as I am concerned, this is a design bug or mis-feature. I to have wanted to do exactly what you were trying to do. I could be wrong but I can't see any reason that it should be hard to implement.
Apr 16 2007
David Ferenczi wrote:BCS wrote:I don't think that there is a bug filed. If you want to, go ahead and file one. I'd mark it as a feature request because I think that the current behavior is "correct" according to the spec.Reply to David,Should we file a bug, or is there one already? (I haven't found)Thank you very much for the quick answer. Maybe I miss some important point, but I don't understand why the processing order explains the behaviour. In my original code the situation looks like this:[...] A nested class can only be derived from by another class nested inside the same class. As far as I am concerned, this is a design bug or mis-feature. I to have wanted to do exactly what you were trying to do. I could be wrong but I can't see any reason that it should be hard to implement.
Apr 16 2007
BCS wrote:David Ferenczi wrote:Where is the spec is this behavior mentioned? Thanks, BradleyBCS wrote:I don't think that there is a bug filed. If you want to, go ahead and file one. I'd mark it as a feature request because I think that the current behavior is "correct" according to the spec.Reply to David, [...] A nested class can only be derived from by another class nested inside the same class. As far as I am concerned, this is a design bug or mis-feature. I to have wanted to do exactly what you were trying to do. I could be wrong but I can't see any reason that it should be hard to implement.Should we file a bug, or is there one already? (I haven't found)
Apr 16 2007
Reply to Bradley,Where is the spec is this behavior mentioned? Thanks, BradleyI can't seem to find it. Maybe I'm just rembering a comment from walter.
Apr 16 2007