Confused about interfaces in D

Thomas Leonard talex5+d at gmail.com
Wed Oct 1 13:59:42 PDT 2008


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"?

Thanks,


More information about the Digitalmars-d-learn mailing list