Implicit conversion from array of class to array of interface
pjdeets2 at gmail.com
Sun Dec 13 01:22:34 PST 2009
On Sun, 13 Dec 2009 04:16:19 -0500, Frank Benoit
<keinfarbton at googlemail.com> wrote:
> 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.
Thanks for informing me, my newer workaround avoids this problem.
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
More information about the Digitalmars-d-learn