Thread overview
Coderiving
Nov 21, 2006
Karen Lanrap
Nov 21, 2006
Sean Kelly
Nov 21, 2006
BCS
Nov 21, 2006
Sean Kelly
Nov 21, 2006
JohnC
Nov 21, 2006
Karen Lanrap
Dec 06, 2006
Karen Lanrap
November 21, 2006
Why one can derive from a nested class only in the corresponding super class?

The example gives the error:
> super class Id is nested within Concept, not Concrete

But Concrete is derived from Concept and should contain the definition of the class Id!


<code>
interface Identifier
{
    char[] whoAmI();
}
class Concept
{
    class Id:Identifier
    {
        char[] whoAmI()
        {
            return "Concept.".dup;
        }
    }
}

class Concrete: Concept
{
    class Idl: Id  //does not work
    {
        char[] whoAmI(){
            return "Concrete.".dup;
        }
    }
}
void main()
{
    auto instance= new Concrete;
}
</code>

November 21, 2006
Karen Lanrap wrote:
> Why one can derive from a nested class only in the corresponding super class?
> 
> The example gives the error:
>> super class Id is nested within Concept, not Concrete
> 
> But Concrete is derived from Concept and should contain the definition of the class Id!

I think this is because inner classes can access data in the private scope of their surrounding class, and private class data should not be accessible by derived classes.


Sean
November 21, 2006
Sean Kelly wrote:
> Karen Lanrap wrote:
>> Why one can derive from a nested class only in the corresponding super class?
>>
>> The example gives the error:
>>> super class Id is nested within Concept, not Concrete
>>
>> But Concrete is derived from Concept and should contain the definition of the class Id!
> 
> I think this is because inner classes can access data in the private scope of their surrounding class, and private class data should not be accessible by derived classes.
> 
> 
> Sean

Based on that argument, this shouldn't work.

<code file="a.d">
private int a;

class Foo
{
	void fig(){a++;}
}
</code>

<code file="b.d">
class Bar : Foo
{
	void bar(){fig():}
}
</code>


The derived nested class would have no more access than any other code. Yes it could access protected stuff by way of of inherited members but that is the way things are supposed to work.
November 21, 2006
"Karen Lanrap" <karen@digitaldaemon.com> wrote in message news:Xns9882A8C0ABB63digitaldaemoncom@63.105.9.61...
> Why one can derive from a nested class only in the corresponding super class?
>
> The example gives the error:
>> super class Id is nested within Concept, not Concrete
>
> But Concrete is derived from Concept and should contain the definition of the class Id!
>
>
> <code>
> interface Identifier
> {
>    char[] whoAmI();
> }
> class Concept
> {
>    class Id:Identifier
>    {
>        char[] whoAmI()
>        {
>            return "Concept.".dup;
>        }
>    }
> }
>
> class Concrete: Concept
> {
>    class Idl: Id  //does not work
>    {
>        char[] whoAmI(){
>            return "Concrete.".dup;
>        }
>    }
> }
> void main()
> {
>    auto instance= new Concrete;
> }
> </code>
>

To make it work, declare Id and Idl with the static attribute.

class Concept {
  static class Id : Identifier { ... }
}

class Concrete : Concept {
  static class Idl : Id { ... }
}


November 21, 2006
BCS wrote:
> Sean Kelly wrote:
>> Karen Lanrap wrote:
>>> Why one can derive from a nested class only in the corresponding super class?
>>>
>>> The example gives the error:
>>>> super class Id is nested within Concept, not Concrete
>>>
>>> But Concrete is derived from Concept and should contain the definition of the class Id!
>>
>> I think this is because inner classes can access data in the private scope of their surrounding class, and private class data should not be accessible by derived classes.
>>
>>
>> Sean
> 
> Based on that argument, this shouldn't work.
> 
> <code file="a.d">
> private int a;
> 
> class Foo
> {
>     void fig(){a++;}
> }
> </code>
> 
> <code file="b.d">
> class Bar : Foo
> {
>     void bar(){fig():}
> }
> </code>
> 
> 
> The derived nested class would have no more access than any other code. Yes it could access protected stuff by way of of inherited members but that is the way things are supposed to work.

I considered this before posting, and perhaps you're right.  Maybe this is just a technical issue, as I suspect the 'outer' pointer is handled differently than how parent class data is accessed.


Sean
November 21, 2006
JohnC wrote:

> To make it work, declare Id and Idl with the static attribute.

Yes this works in this case, but only because Id does not access any outer information?
November 21, 2006
"Karen Lanrap" <karen@digitaldaemon.com> wrote in message news:Xns9882A8C0ABB63digitaldaemoncom@63.105.9.61...
> Why one can derive from a nested class only in the corresponding super class?
>
> The example gives the error:
>> super class Id is nested within Concept, not Concrete
>
> But Concrete is derived from Concept and should contain the definition of the class Id!

Walter's response when I asked for this was "AAAAAAIEEEEE!!!".  He said basically that it's kind of a niche case, and that unless there was a truly demonstrable need for it, he wouldn't try to implement it.


December 06, 2006
Jarrett Billingsley wrote:

> He said basically that it's kind of a niche case, and that unless there was a truly demonstrable need for it, he wouldn't try to implement it.

That is the usual type of argument ... no explanation on what is "truly demonstrable need".

Because one can always revert to non inner classes or even to C-style there might be no such need ever.
December 06, 2006
"Karen Lanrap" <karen@digitaldaemon.com> wrote in message news:Xns989113480AE6Fdigitaldaemoncom@63.105.9.61...

> That is the usual type of argument ... no explanation on what is "truly demonstrable need".
>
> Because one can always revert to non inner classes or even to C-style there might be no such need ever.

Well also we all know how stubborn Walter can be about adding or changing things sometimes.  Though as of late he's been pretty malleable..