interface reference not compatible to Object?
Walter Bright
newshound at digitalmars.com
Sat Oct 21 16:33:55 PDT 2006
Frank Benoit (keinfarbton) wrote:
> interface I{
> void func();
> }
> class C : I {
> void func(){
> }
> }
> void main(){
> C c = new C;
> c.toHash(); // from class Object
> I i = c;
> i.toHash(); // line 14
> }
> /////////////////////////////
> t.d(14): no property 'toHash' for type 't.I'
> t.d(14): function expected before (), not 1 of type int
>
>
> 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.
More information about the Digitalmars-d
mailing list