digitalmars.D.learn - Constructor Inheritance
- Meta (22/22) Jun 20 2016 It's been so long since I've had to use OOP in D that I'm
- ketmar (2/2) Jun 20 2016 no and no. howewer, creating template mixin with default ctors
- H. S. Teoh via Digitalmars-d-learn (7/9) Jun 20 2016 I think Phobos has an AutoImplement template that might do this for you.
- Meta (5/13) Jun 20 2016 I was going to say that this is painful compared to Java or C++,
It's been so long since I've had to use OOP in D that I'm starting to forget things like this. If I have the parent class A which defines a constructor: class A { string val; this(string val) { this.val = val; } } And a child class B which inherits from A: class B: A { } I get the the following error: Error: class B cannot implicitly generate a default ctor when base class A is missing a default ctor Is there a simpler way to do this without having to define a constructor in B that just forwards to A's constructor, like so? class B: A { this(string val) { super(val); } } Is it allowed to do something like `alias __ctor = super.__ctor`?
Jun 20 2016
no and no. howewer, creating template mixin with default ctors may spare you of some typing.
Jun 20 2016
On Tue, Jun 21, 2016 at 02:48:39AM +0000, ketmar via Digitalmars-d-learn wrote:no and no. howewer, creating template mixin with default ctors may spare you of some typing.I think Phobos has an AutoImplement template that might do this for you. Maybe take a look in std.typecons or std.meta (or wherever they shove those things these days)? T -- "Hi." "'Lo."
Jun 20 2016
On Tuesday, 21 June 2016 at 03:06:22 UTC, H. S. Teoh wrote:On Tue, Jun 21, 2016 at 02:48:39AM +0000, ketmar via Digitalmars-d-learn wrote:I was going to say that this is painful compared to Java or C++, but it looks like it's been too long since I've used those languages as well; neither of them allow constructor inheritance (but C++ has a syntax for doing it explicitly).no and no. howewer, creating template mixin with default ctors may spare you of some typing.I think Phobos has an AutoImplement template that might do this for you. Maybe take a look in std.typecons or std.meta (or wherever they shove those things these days)? T
Jun 20 2016