Object and interface compatibility
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Sun Feb 11 00:51:55 PST 2007
Jarrett Billingsley wrote:
> "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.
But isn't this only true for COM interfaces? The compiler knows when
compiling "i.toHash();" whether or not typeof(i) is an interface
inheriting from IUnknown, doesn't it? So it could make this work for all
other interfaces...
> 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.
It's much easier solved by checking if "IUnknown" is a base of the
interface in question.
More information about the Digitalmars-d
mailing list