digitalmars.D.learn - Coderiving
- Karen Lanrap (34/35) Nov 21 2006 Why one can derive from a nested class only in the corresponding
- Sean Kelly (5/13) Nov 21 2006 I think this is because inner classes can access data in the private
- BCS (18/34) Nov 21 2006 Based on that argument, this shouldn't work.
- Sean Kelly (5/45) Nov 21 2006 I considered this before posting, and perhaps you're right. Maybe this
- JohnC (9/44) Nov 21 2006 To make it work, declare Id and Idl with the static attribute.
- Karen Lanrap (3/4) Nov 21 2006 Yes this works in this case, but only because Id does not access any
- Jarrett Billingsley (5/11) Nov 21 2006 Walter's response when I asked for this was "AAAAAAIEEEEE!!!". He said
- Karen Lanrap (5/8) Dec 05 2006 That is the usual type of argument ... no explanation on what is
- Jarrett Billingsley (4/8) Dec 05 2006 Well also we all know how stubborn Walter can be about adding or changin...
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 ConcreteBut 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>
Nov 21 2006
Karen Lanrap wrote:Why one can derive from a nested class only in the corresponding super class? The example gives the error: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. Seansuper class Id is nested within Concept, not ConcreteBut Concrete is derived from Concept and should contain the definition of the class Id!
Nov 21 2006
Sean Kelly wrote:Karen Lanrap wrote: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.Why one can derive from a nested class only in the corresponding super class? The example gives the error: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. Seansuper class Id is nested within Concept, not ConcreteBut Concrete is derived from Concept and should contain the definition of the class Id!
Nov 21 2006
BCS wrote:Sean Kelly wrote: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. SeanKaren Lanrap wrote: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.Why one can derive from a nested class only in the corresponding super class? The example gives the error: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. Seansuper class Id is nested within Concept, not ConcreteBut Concrete is derived from Concept and should contain the definition of the class Id!
Nov 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: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 { ... } }super class Id is nested within Concept, not ConcreteBut 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>
Nov 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?
Nov 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: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.super class Id is nested within Concept, not ConcreteBut Concrete is derived from Concept and should contain the definition of the class Id!
Nov 21 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.
Dec 05 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..
Dec 05 2006