Segfault when casting array of Interface types
    rcor via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Mon Sep 15 19:21:40 PDT 2014
    
    
  
I'm back for another round of "is this a bug, or am I doing 
something stupid?".
C and D implement interface I, and I have an array of each. I'd 
like to combine these into one I[], but eventually I'd like to 
cast an element back to its original type.
interface I {}
class C : I {}
class D : I {}
void main() {
   C[] c = [new C, new C];
   D[] d = [new D, new D];
   auto i = cast(I[]) c ~ cast(I[]) d;
   assert(cast(C) i[0]); // segfault
}
casting each array to I[] is fine, but casting an element back to 
C segfaults (even if it weren't a C, it should just return null, 
right?)
    
    
More information about the Digitalmars-d-learn
mailing list