nested class inheritance

Gor Gyolchanyan gor.f.gyolchanyan at gmail.com
Fri Jul 13 12:19:55 PDT 2012


On Fri, Jul 13, 2012 at 11:10 PM, Andrei Alexandrescu <
SeeWebsiteForEmail at erdani.org> wrote:

> On 7/13/12 3:07 PM, Gor Gyolchanyan wrote:
>
>> On Fri, Jul 13, 2012 at 11:03 PM, Andrei Alexandrescu
>> <SeeWebsiteForEmail at erdani.org <mailto:SeeWebsiteForEmail@**erdani.org<SeeWebsiteForEmail at erdani.org>
>> >>
>>
>> wrote:
>>
>>     On 7/13/12 2:30 PM, Gor Gyolchanyan wrote:
>>
>>         The whole point is to have it not static. I need it to be properly
>>         nested with the this.outer.
>>
>>
>>     What would be the type of this.outer?
>>
>>     Andrei
>>
>>
>> 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.
>
> Andrei
>
>
Why? The this.outer would be the same object from both perspectives. The
difference is, that the Fruit.Seed would see it as Fruit and the AppleSeed
would see it as Apple. And If someone derived from Apple and AppleSeed (say
RedAple and RedAppleSeed), the RedAppleSeed would see the exact same
object, except typed as RedApple.

When you create a new AppleSeed, you need to create it from an Apple or
something derived from an Apple. This ensures, that every seed sees the
correct fruit as the correct type.

-- 
Bye,
Gor Gyolchanyan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120713/9601360e/attachment-0001.html>


More information about the Digitalmars-d mailing list