D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1462 - Templated constructor not supported
Summary: Templated constructor not supported
Status: RESOLVED DUPLICATE of issue 435
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 enhancement
Assignee: No Owner
URL:
Keywords: spec
Depends on:
Blocks:
 
Reported: 2007-08-31 09:33 UTC by Reiner Pope
Modified: 2015-06-09 01:14 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Reiner Pope 2007-08-31 09:33:31 UTC
I know of no way to create a templated constructor for a class. (This is useful, for instance, with variadic template args). The following code fails to parse in compilation:

class Foo
{
    this(T...)(T t) {}
}
Comment 1 Stewart Gordon 2008-09-09 12:32:08 UTC
The problem seems to be that the current D syntax doesn't support it:

Constructor:
	this Parameters FunctionBody

Parameters:
	( ParameterList )
	( )

The alternative would be

class Foo
{
    template(T...) this {
        this(T t) {}
    }
}

except that this doesn't work because 'this' is a keyword, not an identifier.
Comment 2 Steven Schveighoffer 2010-08-05 10:57:21 UTC

*** This issue has been marked as a duplicate of issue 435 ***