[Issue 12737] static constructor requires call of super constructor
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon May 12 12:59:08 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=12737
Jonathan M Davis <jmdavisProg at gmx.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |jmdavisProg at gmx.com
Resolution|--- |INVALID
--- Comment #1 from Jonathan M Davis <jmdavisProg at gmx.com> ---
No, this isn't a bug in the compiler, and it doesn't have anything to do with
static constructors. It's a bug in your code. This would fail to compile with
the same error:
class A {
this(int a) {
}
}
class B : A {
}
void main() {
auto n = new B();
}
The problem is that B's constructor must call A's constructor, but a
compiler-generated default constructor (which is all B is going to have,
because you didn't declare one for it) can only call default constructors for
its base class, and A doesn't have one. It has a constructor which takes an
int. So, you have to either add a default constructor to A or add an explicit
default constructor to B which calls A's constructor with an int of whatever
value would be appropriate.
--
More information about the Digitalmars-d-bugs
mailing list