Forwarding constructor arguments to super

bearophile bearophileHUGS at lycos.com
Mon Jun 14 04:05:42 PDT 2010


pillsy:
> Is there a good way to forward constructor arguments to a superclass constructor?

This seems to work for simple situations, but maybe it doesn't work in more complex cases:


import std.traits: ParameterTypeTuple;

mixin template This() {
    this(ParameterTypeTuple!(super.__ctor) args) { super(args); }
}

class Foo {
    int _x;
    float _f;

    this(int x, float f) {
        this._x = x;
        this._f = f;
    }
}

class Bar : Foo {
    mixin This;
}

void main() {
    auto b = new Bar(10, 1.5);
}

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list