www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - how to resolve "matches more than one template declaration"?

reply "Juanjo Alvarez" <juanjux gmail.com> writes:
Hi,

Newbie question:

void foo(S)(S oneparam){}
void foo(S)(S oneparam, int anotherParam){}
alias fooStr = foo!string;

Gives:

"Error: template test.foo matches more than one template 
declaration:"

How could I fix it so the alias aliases one of the two versions? 
Also, why can't "fooStr" be an alias for both templates? 
Considering than the generic parameter is not what changes 
between both, I tough I could do fooStr(somestring) or 
fooStr(somestring, someint) with this alias.
Jun 20 2014
parent Jonathan M Davis via Digitalmars-d-learn writes:
On Fri, 20 Jun 2014 20:40:49 +0000
Juanjo Alvarez via Digitalmars-d-learn <digitalmars-d-learn puremagic.com>
wrote:

 Hi,

 Newbie question:

 void foo(S)(S oneparam){}
 void foo(S)(S oneparam, int anotherParam){}
 alias fooStr = foo!string;

 Gives:

 "Error: template test.foo matches more than one template
 declaration:"

 How could I fix it so the alias aliases one of the two versions?
 Also, why can't "fooStr" be an alias for both templates?
 Considering than the generic parameter is not what changes
 between both, I tough I could do fooStr(somestring) or
 fooStr(somestring, someint) with this alias.
void foo(S)(S oneparam) {} is equivalent to template foo(S) { void foo(S oneparam) {} } so do this: template foo(S) { void foo(S oneparam){} void foo(S oneparam, int anotherParam){} } alias fooStr = foo!string; - Jonathan M Davis
Jun 20 2014