Confused about interfaces in D

Bill Baxter wbaxter at gmail.com
Wed Oct 1 14:12:26 PDT 2008


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'
>
> This compiles, though:
>
>        Clock c = new SystemClock();
>        (cast(Object) c).toString();
>
> 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.

--bb


More information about the Digitalmars-d-learn mailing list