www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - [Bug or feature] nested class inheritance

reply David Ferenczi <raggae ferenczi.net> writes:
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
parent reply Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----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?
Yes
 Does 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
next sibling parent reply Bradley Smith <digitalmars-com baysmith.com> writes:
Thomas Kuehne wrote:
 -----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?
Yes
 Does 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
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 B
Apr 15 2007
parent janderson <askme me.com> writes:
Bradley Smith wrote:
 Thomas Kuehne wrote:
 -----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?
Yes
 Does 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
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 B
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
Apr 16 2007
prev sibling parent reply David Ferenczi <raggae ferenczi.net> writes:
 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?
Yes
 Does 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
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, David
Apr 15 2007
parent reply BCS <ao pathlink.com> writes:
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
parent reply David Ferenczi <raggae ferenczi.net> writes:
BCS wrote:

 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.
Should we file a bug, or is there one already? (I haven't found)
Apr 16 2007
parent reply BCS <BCS pathlink.com> writes:
David Ferenczi wrote:
 BCS wrote:
 
 
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.
Should we file a bug, or is there one already? (I haven't found)
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.
Apr 16 2007
parent reply Bradley Smith <digitalmars-com baysmith.com> writes:
BCS wrote:
 David Ferenczi wrote:
 BCS wrote:


 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)
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.
Where is the spec is this behavior mentioned? Thanks, Bradley
Apr 16 2007
parent BCS <ao pathlink.com> writes:
Reply to Bradley,

 Where is the spec is this behavior mentioned?
 
 Thanks,
 Bradley
I can't seem to find it. Maybe I'm just rembering a comment from walter.
Apr 16 2007