nested class inheritance

Benjamin Thaut code at benjamin-thaut.de
Sat Jul 14 10:20:12 PDT 2012


Am 14.07.2012 19:18, schrieb Gor Gyolchanyan:
> On Sat, Jul 14, 2012 at 9:12 PM, Benjamin Thaut <code at benjamin-thaut.de
> <mailto:code at benjamin-thaut.de>> wrote:
>
>     The only problem about this is:
>
>     class Fruit
>     {
>        class Seed {
>          void SetFruit(Fruit fruit)
>          {
>            this.outer = fruit;
>          }
>        }
>     }
>
>     class Apple: Fruit
>     {
>        void AppleOnlyMethod(){ ... }
>
>        class AppleSeed: Fruit.Seed {
>          void DoSomething()
>          {
>            AppleOnlyMethod();
>          }
>        }
>
>        auto GetNewSeed() { return new AppleSeed(); }
>     }
>
>     auto apple = new Apple();
>     auto seed = apple.GetNewSeed();
>     seed.SetFruit(new Fruit());
>     seed.DoSomething(); //what happens here?
>
>     Kind Regards
>     Benjamin Thaut
>
>
> I think this.outer is not an lvalue, which solves the problem. It
> wouldn't make sense to have it an lvalue, because the object is
> specifically created out of the initial outer object.
>
> --
> Bye,
> Gor Gyolchanyan.

The last time I checked you could reassign outer ;-)



More information about the Digitalmars-d mailing list