[Bug or feature] nested class inheritance
David Ferenczi
raggae at ferenczi.net
Sun Apr 15 10:03:08 PDT 2007
>> 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:
> # (http://www.digitalmars.com/d/function.html)
> # Unlike module level declarations, declarations within function scope
> # are processed in order.
> #
>
> 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
More information about the Digitalmars-d-learn
mailing list