It is not possible to make constructors as template functions. As constructor does not differ so much from function it should not be very difficult to implement it, but gives lot more flexibility.
Comment #1 by andrei — 2009-05-18T12:31:07Z
A quick unittest:
class B
{
this(int) {}
}
class D : B
{
this(A...)(A args) { super(args); }
}
unittest
{
auto a = new D(4);
}
Comment #2 by schveiguy — 2010-08-05T10:57:21Z
*** Issue 1462 has been marked as a duplicate of this issue. ***
Comment #3 by nfxjfg — 2010-09-21T04:59:11Z
*** Issue 4905 has been marked as a duplicate of this issue. ***
Comment #4 by rsinfu — 2010-10-25T11:39:57Z
Created attachment 794
Patch against dmd trunk r727, for D2
This is a D2 enhancement patch. Passed dmd/druntime/phobos tests and testcases in the reports.
class.c: Just added isTemplateDeclaration() to an if condition. It makes the ClassDeclaration recognize constructor templates as its constructors.
expression.c: Changed toParent() to isThis(). toParent() doesn't check through template instances and misunderstands that constructor is not declared inside a class or struct. isThis() (or toParent2) takes care of such cases.
Comment #5 by sweatygarlic — 2011-05-15T09:57:25Z
Created attachment 973
this is a modification to initialize const member
this contains the diff of `794: Patch against dmd trunk r727, for D2'
Comment #6 by mathias.baumann — 2011-10-03T04:59:29Z
This fix seems to have not made it to dmd v1.071
Could D1 also be fixed, please?
--Marenz
Comment #7 by kennytm — 2012-02-09T14:07:28Z
*** Issue 4531 has been marked as a duplicate of this issue. ***