overloading function with function templates
    mstrlu 
    skateBBH at yahoo.com
       
    Thu Dec 27 15:42:57 PST 2007
    
    
  
Hello,
I  just discovered that its not possible to write a function template with the same identifier as an existing function ( even though the function arguments are different ):
import std.stdio;
 
void test(int x)( int y ){
    writefln( "tmpl:", x, " val:", y);
}
int test(){
    return 15;
}
int main(){    
    writefln( test() );
    test!(2)(3);
    return 0;
}
with gdc 0.24 or dmd 1.023 I get "template_test.d(8): function template_test.test conflicts with template template_test.test(int x) at template_test.d(4)"
in c++ this doesn't seem to be a problem:
#include <iostream>
using namespace std;
template < int x > 
void test( int y ){
    cout << "tmpl:" << x << " val:" << y << endl;
}
int test(){
    return 15;
}
int main(){
    cout << test() << endl;
    test<2>( 3 );
}
works fine.
Isn't it possible to resolve the function templates before checking for ambiguous identifiers in D?  Is there something in the documetation on this subject that I did miss?
thank you
    
    
More information about the Digitalmars-d-learn
mailing list