On 11/29/2016 12:04 PM, Arafel wrote:
> I think I might be a bit late to the party, and I'm still quite new in
> D... but wouldn't a variadic template constructor work? The usual rules
> of templates would still let you override a constructor if needed.
>
> ---
> class A {
> this() { }
> this(int a) { }
> }
> class B : A {
> // Here we inherit all of A's constructors.
> this(Args...)(Args args) {
> super(args);
> }
> this(string s) { }
> }
> void main() {
> B b1 = new B(42);
> B b2 = new B("foo");
> }
> ---
>
> I've been playing with it, and the only problems I can see are with
> specialization and casting (i.e. B defines this(float), but you want to
> call A's this(int), the int will be promoted to float and B's version
> will be used). A way of disabling them would be needed, though...
> perhaps assert(0)?Have just answered a similar question in a PR thread: https://github.com/dlang/DIPs/pull/42#issuecomment-263562276
signature.asc
Description: OpenPGP digital signature
