April 06, 2009
Hi All,

can I cast a LinkSeq from inherited type to base type?

------------------------ code --------------------------
   class Fruit {}
   class Apple: Fruit {}

   auto apples = new LinkSeq!(Apple);
   apples.append(new Apple);
   assert(apples !is null);
   assert(apples.length == 1);

   auto fruits = cast(LinkSeq!(Fruit))(apples);
   assert(fruits !is null); // <--- failed
   assert(fruits.length == 1);
------------------------ code --------------------------


--Qian
April 06, 2009
Qian Xu wrote:
> Hi All,
> 
> can I cast a LinkSeq from inherited type to base type?

What I can do, is to create a new LinkSeq!(Fruit) and then cast all elements one by one.


-- 
Xu, Qian (stanleyxu)
 http://stanleyxu2005.blogspot.com
Top | Discussion index | About this forum | D home