Confused about interfaces in D

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


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();

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


More information about the Digitalmars-d-learn mailing list