www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Template conflict with Function

reply Matthias Walter <walter mail.math.uni-magdeburg.de> writes:
Hello,

I've got another question regarding templates. I have the following functions:

int foo (int i)
{

}

int foo (T, U) (inout Expression !(T, U) expr)
{

}

The compiler stops with error: "template Test.foo(T,U) conflicts with function
Test.foo at Test.d(191)".

I'd like to call them in the following way:

foo (10);
Expression !(long, int) x;
foo (x);

I also cannot put them into one function template, because the parameter
storage class es differ.

best regards
Matthias Walter
Feb 13 2008
parent reply Kirk McDonald <kirklin.mcdonald gmail.com> writes:
Matthias Walter wrote:
 Hello,
 
 I've got another question regarding templates. I have the following functions:
 
 int foo (int i)
 {
 
 }
 
 int foo (T, U) (inout Expression !(T, U) expr)
 {
 
 }
 
 The compiler stops with error: "template Test.foo(T,U) conflicts with function
Test.foo at Test.d(191)".
 
 I'd like to call them in the following way:
 
 foo (10);
 Expression !(long, int) x;
 foo (x);
 
 I also cannot put them into one function template, because the parameter
storage class es differ.
 
 best regards
 Matthias Walter
Re-write the first one as: int foo()(int i) { } That is, make it another, second function template, with no template parameters. -- Kirk McDonald http://kirkmcdonald.blogspot.com Pyd: Connecting D and Python http://pyd.dsource.org
Feb 13 2008
parent reply bearophile <bearophileHUGS lycos.com> writes:
Kirk McDonald:
 int foo()(int i) {
 }
 That is, make it another, second function template, with no template
parameters.
If not already present, I think this little trick deserves to go into the D docs :-) Bye, bearophile
Feb 13 2008
parent Bill Baxter <dnewsgroup billbaxter.com> writes:
bearophile wrote:
 Kirk McDonald:
 int foo()(int i) {
 }
 That is, make it another, second function template, with no template
parameters.
If not already present, I think this little trick deserves to go into the D docs :-)
Until then there's always the Comments wiki page. --bb
Feb 13 2008