digitalmars.D.learn - (D1) Mixing in constructors
- Justin Whear (22/22) Nov 06 2009 I've been trying to use a template to mixin constructors and running int...
I've been trying to use a template to mixin constructors and running into what seems like a bug. Here's the template: public template ChainNodeSubclassing { this() { super(); } this(string id) { super(id); } ...some other stuff... } Using this, compilation would always fail and complain that Object has no super class. This is strange because template mixins are supposed to only be evaluated where they're mixed-in, namely in the body of my classes which certainly do have super-classes. So I tried getting around it like this (just the second constructor for brevity): this(string id) { static if (!is(typeof(this) : Object)) { super(id); writefln("Instantiating %s with ID", this.classinfo.name); } else { throw new Exception("Cannot instantiate type"); } } Now it compiles, but I always get errors at runtime when I try to create of one the classes with this mixin. It seems that every object is implicitly convertible to Object. Is this a bug or am I doing something really wrong?
Nov 06 2009