On Fri, Jul 13, 2012 at 10:25 PM, Era Scarecrow <rtcvb32@yahoo.com> wrote:
On Friday, 13 July 2012 at 18:00:05 UTC, Gor Gyolchanyan wrote:
Doesn't this make sense?

class Fruit
{
    class Seed { }
}

class Apple: Fruit
{
     class AppleSeed: Fruit.Seed { }
}

This means, that as Fruit.Seed needs access to enclosing Fruit, AppleSeed, being a Fruit.Seed will also have access to enclosing Fruit, which is Apple.
DMD 0.259 has this to say:

Error: class main.Apple.AppleSeed is nested within Apple, but  super class Seed is nested within Fruit

Which doesn't make sense, IMO. What do you guys think about this? Who makes more sense me or DMD 2.059?

 I'd say DMD makes more sense. Seed has knowledge of itself AND Fruit. So if it's following the same rules and for how it makes sense, then unless you add static to Seed, then you won't get it to work. Reminds me of when I used Java years ago experimenting with inner classes, came to a distinct conclusion of object referencing and why it didn't want to work without an outer object.

 Consider: fails on seed, not seed2.

class Fruit {
 int x;
 class Seed {
  void oneMoreToX() {
   x++; //knows about Fruit.x, even if not instantiated
  }
 }

 static class Seed2 {
  void oneMoreToX() {
//  x++; //fails to compile, no knowledge of Fruit
  }
 }
}

class Apple: Fruit {
 class AppleSeed: Fruit.Seed { } //fails (no outer object (Fruit.x) and makes no sense)
 class AppleSeed2: Fruit.Seed2 { } //works fine
}

I need Seed to have a reference to Fruit because there will be more then one derivative of Seed in the same derivative of Fruit and they all need to store data inside the fruit and communicate with each other in that way. That's why Seed can't be static. What can I do to have multiple seeds in the same fruit with all seed-fruit-seed communication hidden in the base classes?

--
Bye,
Gor Gyolchanyan.