Constructor Inheritance
Meta via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jun 20 19:27:51 PDT 2016
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`?
More information about the Digitalmars-d-learn
mailing list