Thread overview | |||||
---|---|---|---|---|---|
|
November 26, 2008 Inheriting from a nested class | ||||
---|---|---|---|---|
| ||||
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; } } |
November 26, 2008 Re: Inheriting from a nested class | ||||
---|---|---|---|---|
| ||||
Posted in reply to llee | 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; } } >} |
November 26, 2008 Re: Inheriting from a nested class | ||||
---|---|---|---|---|
| ||||
Posted in reply to llee | 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.
|
Copyright © 1999-2021 by the D Language Foundation