Inheriting from a nested class
    Frank Benoit 
    keinfarbton at googlemail.com
       
    Wed Nov 26 13:43:45 PST 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.
    
    
More information about the Digitalmars-d-learn
mailing list