[Bug or feature] nested class inheritance
janderson
askme at me.com
Mon Apr 16 00:12:10 PDT 2007
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:
>> # (http://www.digitalmars.com/d/function.html)
>> # Unlike module level declarations, declarations within function scope
>> # are processed in order.
>> #
>>
>> 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
More information about the Digitalmars-d-learn
mailing list