Implicit conversion from array of class to array of interface
Frank Benoit
keinfarbton at googlemail.com
Sun Dec 13 01:16:19 PST 2009
casting an array of class references to an array of interface references
(or vice versa) will not work at runtime. Your program will crash.
This is because if the invisible pointer correction that is done if you
cast a single class ref to an interface ref.
C c = new C;
I i = c;
writefln( "c=%d i=%i", cast(uint)cast(void*)c, cast(uint)cast(void*)i);
This shows, the numeric values are not equal.
At the assignment were an imlicit cast is taking place, dmd inserts a
pointer adjustement. If you cast an array, nothing physically is done to
the array content. In fact you need to run a loop over the array and
cast each member on it own.
More information about the Digitalmars-d-learn
mailing list