digitalmars.D.learn - Inheriting from a nested class
- llee <larry workingwondersus.com> Nov 26 2008
- BCS <ao pathlink.com> Nov 26 2008
- Frank Benoit <keinfarbton googlemail.com> Nov 26 2008
Is it possible to inherit from a nested class from outside of the enclosing
class? For example:
class A
{
class B { int x; }
}
class C : B
{
int get () { return x; }
}
Nov 26 2008
Reply to llee,Is it possible to inherit from a nested class from outside of the enclosing class? For example: class A { class B { int x; } } class C : B { int get () { return x; } }
no, sorry that wouldn't work well anyway as the binding to A might get tricky OTOH this would be really nice.class A { class B { int x; } } class C : A { class D : B { int get () { return x; } } }
Nov 26 2008
llee schrieb:Is it possible to inherit from a nested class from outside of the enclosing class? For example: class A { class B { int x; } } class C : B { int get () { return x; } }
It should work if B is a static class and you refer to it with A.B . class A { static class B { int x; } } class C : A.B { int get () { return x; } } If the class is not static, it has an implicit "this" pointer of the surrounding class (like in Java), so you cannot create instances of non-static B, if there is no instance of A. static make B independent of this reference.
Nov 26 2008









BCS <ao pathlink.com> 