Interface factory

BCS ao at pathlink.com
Tue Aug 14 10:26:19 PDT 2007


Reply to luke,

> But i think the type should be valid because it implements the
> interface B.
> 
> Or am i wrong about the whole thing?
> 

this code IS valid:

interface A{}
interface B: A{}
class C : B{}
B Factory()
{
return new C();
}

auto i = cast(A)Factory();

Factory news a C, casts it to a B, and returns it
then it is cast to an A and assigned.

All OK

the issue is when you coast a function returning an interface to a function 
returning another interface.

When you do this the cast from the original type to the new type never happens, 
the reference is copied directly. However because of how interfaces are implemented 
this gives incorrect results. (The details were brought up in a thread about 
4 or 5 days ago)




More information about the Digitalmars-d-learn mailing list