cast a LinkSeq
Daniel Keep
daniel.keep.lists at gmail.com
Mon Apr 6 16:42:54 PDT 2009
Qian Xu wrote:
> Adam Burton wrote:
>> I wouldn't think so, cos LinkSeq!(Apple) does not inherit
>> LinkSeq!(Fruit), they are 2 separate types. However your apples
>> automatically downcast (or up, depending which way you like to draw
>> your diagrams :-) ) so unless you intend to pass the LinkSeq!(Apple)
>> into a function expecting LinkSeq!(Fruit) it shouldn't be a problem.
>> If you are passing about LinqSeq!(Fruit) and want your
>> LinkSeq!(Apple) to fit you might need to write some adapters and make
>> use of the models available to you or something along them lines.
>>
>> That's my understanding anyway.
>
>>
>
> yes. I can cast all Apple-object to Fruit-objects one by one. I hope
> there is an one-line-solution :-)
You can't do it. Imagine you cast your LinkSeq!(Apple) to
LinkSeq!(Fruit). You can now add a Banana to your LinkSeq!(Fruit), thus
corrupting the original object.
You get a similar problem with arrays.
The most direct way would probably be to create a LinkSeqView!(T) class
which did the cast on the fly and prohibited mutating operations.
-- Daniel
More information about the Digitalmars-d-learn
mailing list