Bug 3790 – [OOP] Forwarding constructors to super class
Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2010-02-09T18:16:32Z
Last change time
2019-11-06T14:46:13Z
Assigned to
No Owner
Creator
iorlas
Comments
Comment #0 by denis.tomilin — 2010-02-09T18:16:32Z
Constructor of child class cannot pass arguments into parent constructor.
See the example:
class A{
final this(int a=0){
writeln(a);
}
}
class B:A{
}
B b = new B(); //prints 0
B b2 = new B(2); //throws an error "expected 0 arguments, not 1..."
As we can see, logic is normal, but not in dmd. This bug creates a new bug:
class A{
final this(int a=0){
writeln(a);
}
}
class B:A{
this(int a=0){ //compiler perfectly, but parent constructor marked as "final"
super(a);
}
}
It might be not a hard problem, but it will be good for my project to create a logical, nice-look code.
Comment #1 by denis.tomilin — 2010-02-09T20:05:05Z
Also, if we dont give argument a default value, we get an error:
Error: constructor main.B.this no match for implicit super() call in constructor
As i think, somebody thinks in different way with a lot of stones and problems =/
Comment #2 by clugdbug — 2010-11-12T05:03:07Z
This bug report has two issues:
(1) an enhancement request: allow constructors to be inherited.
and
(2) an accepts-invalid bug: 'final this()' is accepted, even though this() is _always_ final.
Downgrading to enhancement.
Comment #3 by braddr — 2011-02-06T15:40:22Z
Mass migration of bugs marked as x86-64 to just x86. The platform run on isn't what's relevant, it's if the app is a 32 or 64 bit app.
Comment #4 by dmitry.olsh — 2018-05-16T14:51:02Z
This is basically a feature request for forwarding of constructors.
C++ has it with `using` statement, D might do it with `alias`.
Comment #5 by razvan.nitu1305 — 2019-11-06T14:46:13Z
Closing on the basis of Dmitry's proposed solution.