Object and interface compatibility

Jarrett Billingsley kb3ctd2 at yahoo.com
Sat Feb 10 17:15:13 PST 2007


"Frank Benoit (keinfarbton)" <benoit at tionex.removethispart.de> wrote in 
message news:eqkuqa$3v1$1 at digitaldaemon.com...
>
> Interfaces are NOT compatible to Object.
>
> interface I{
> void func();
> }
> class C : I {
> void func(){}
> }
>
> void main(){
> I i = new C;
> i.func();                 // OK
> i.toHash();               // error !!
> (cast(C)i).toHash();      // OK
> (cast(Object)i).toHash(); // OK
> }
>
> I think this is a failure in the language design. What do you think?

I think it's because an interface may or may not be pointing to a D object. 
If you create a COM interface, for example, there's no associated D object, 
so there's no way for D to create a hash for it.  It's basically just a 
pointer.

This could be solved by having a "cominterface" type which behaves like 
interfaces currently do, and change interfaces to be more integrated into D. 
Probably never going to happen. 





More information about the Digitalmars-d mailing list