interface reference not compatible to Object?

Lionello Lunesu lio at lunesu.remove.com
Mon Oct 23 08:01:09 PDT 2006


Jari-Matti Mäkelä wrote:
> Walter Bright wrote:
>> Frank Benoit (keinfarbton) wrote:
>>> Is this the intended behaviour? If *every* object in D is a Object, then
>>> every interface reference refers to an Object also.
>>> This said, the above should compile?
>> Replace:
>>     i.toHash();
>> with:
>>     (cast(Object)i).toHash();
>> and it will work, *provided* that i is actually an instance of an
>> Object. If it is not, for example if it came from some COM DLL, the cast
>> will fail.
> 
> Is there much hope that the compiler will make the cast implicitly in
> the future releases?

An interface's vftbl doesn't have toString and others. It does however 
have some RTTI which means a (dynamic_) cast can be used to find the 
pointer to the Object class, but only if it is part of an Object.

This information is only available at run-time. It should not be 
implicit, since it might not succeed.

L.



More information about the Digitalmars-d mailing list