nested class inheritance

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Jul 13 12:30:59 PDT 2012


On 7/13/12 3:18 PM, Christophe Travert wrote:
> Andrei Alexandrescu , dans le message (digitalmars.D:172280), a écrit :
>>> For Fruit.Seed it's Fruit, for AppleSeed it's Apple. This makes sense
>>> because the Apple, which AppleSeed sees is the same object, which
>>> Fruit.Seed sees as it's base type Fruit.
>>
>> That would mean AppleSeed has two outer fields: a Fruit and an Apple.
>
> Only one. Apple. And when AppleSeed.super seed this Apple, it sees a
> fruit.
>
> AppleSeed a;
> assert(is(typeof(a.outer) == Apple));
> assert(is(typeof(a.super) == Seed));
> assert(is(typeof(a.super.outer) == Fruit));
> //but:
> assert(a.outer is a.super.outer);
>
> If you can't figure out how can a.outer and a.super.outer have two
> different types, but be the same, think about covariant return.

Makes sense, thanks.

Andrei



More information about the Digitalmars-d mailing list