Forwarding constructor arguments to super
pillsy
pillsbury at gmail.com
Sat Jun 12 13:50:00 PDT 2010
Is there a good way to forward constructor arguments to a superclass constructor? I.e., if I have
something like this
class Foo {
int _x;
this (int x) { _x = x; }
}
class Bar : Foo {}
I'd like to able to have this just work:
auto bar = new Bar(3);
However, doing this means that DMD complains that Bar.this isn't callable with an int argument. The
next thing I tried was
class Bar : Foo
{
this (Args) (Args... args) { super(args): }
}
at which point DMD complains that constructor Bar.this conflicts with template Bar.__ctor(Args...). I'm
using DMD 2.046, if it matters.
Thank you,
Pillsy
More information about the Digitalmars-d-learn
mailing list