Confused about interfaces in D

Thomas Leonard talex5+d at gmail.com
Thu Oct 2 09:43:03 PDT 2008


On Thu, 02 Oct 2008 06:12:26 +0900, Bill Baxter wrote:

> On Thu, Oct 2, 2008 at 5:59 AM, Thomas Leonard <talex5+d at gmail.com>
> wrote:
>> Hi,
>>
>> I'm used to interfaces in Java, and I'm wondering why this doesn't work
>> in D:
>>
>>  interface Clock {}
>>
>>  class SystemClock : Clock {}
>>
>>  void main(string[] args) {
>>        Clock c = new SystemClock();
>>        c.toString();
>>  }
>>
>> It says:
>>
>>  $ dmd clock.d
>>  clock.d(7): Error: no property 'toString' for type 'clock.Clock'

>> When is a "Clock" not an "Object"?
> 
> When it's derived from IUnknown, a special case put in to support COM
> interfaces on Win32.
> I've not heard anyone voice support for this particular design decision.
> I suppose it's very convenient if you happen to be a COM programmer, but
> I'm not sure why a vendor-specific technology like COM should get such
> special treatment in a language spec.

Ah, I see.

I'm not too worried about COM support, so I edited mtype.c to return 
MATCHconvert whenever the target is Object. That fixes it for me:

http://repo.or.cz/w/delight/core.git?a=commit;h=4e5750a980ef24b65284342f51f549a9d23dc282

Thanks!


More information about the Digitalmars-d-learn mailing list