www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Inheriting from a nested class

reply llee <larry workingwondersus.com> writes:
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
next sibling parent BCS <ao pathlink.com> writes:
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
prev sibling parent Frank Benoit <keinfarbton googlemail.com> writes:
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