Unwanted conflict

Jonathan M Davis jmdavisProg at gmx.com
Sat Jul 20 17:07:55 PDT 2013


On Sunday, July 21, 2013 00:10:40 Carl Sturtivant wrote:
> struct A {
> 	string s;
> 	int n;
> 	this( string s) { this.s = s; }
> 	this( int k)( int n) { this.n = n - k; }
> }
> 
> compiled with dmd gives an error message as follows.
> 
> constr_conflict.d(5): Error: template
> constr_conflict.A.__ctor(int k)(int n) conflicts with constructor
> constr_conflict.A.this at constr_conflict.d(4)
> 
> The exact details seem unimportant except that one constructor
> has compile-time parameters and the other does not.
> 
> What is the conflict exactly?

As of 2.063, you can't overload a templated function with a non-templated 
function (or vice versa). That bug has finally been fixed in git master, but it 
hasn't been released yet. The typical way to workaround the problem is to 
templatize the non-templated function, which you can do by giving it an empty 
template parameter list.

this()(string S) {...}

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list