DIP1004: Inherited Constructors

Dicebot via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Tue Nov 29 04:53:20 PST 2016


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-announce/attachments/20161129/f02684c1/attachment.sig>


More information about the Digitalmars-d-announce mailing list