Conflict between function and template with the same name
Uranuz via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jun 29 00:16:09 PDT 2014
I have a question about this example code;
import std.stdio;
string getByName(string name)
{
return "smth";
}
template getByName(string name)
{
enum
//string
getByName = getByName(name);
}
void main()
{
writeln(getByName!("name"));
}
This produces compilation output:
/d967/f983.d(13): Error: forward reference of variable getByName
/d967/f983.d(19): Error: template instance f983.getByName!"name"
error instantiating
Uncommenting line *//string* changes message to:
Compilation output:
/d976/f558.d(13): Error: recursive evaluation of getByName(name)
/d976/f558.d(19): Error: template instance f558.getByName!"name"
error instantiating
Is there any reason why function and template conflict. They
using different syntax to *call*. For template we have *!* but
for function we don't have it. So why compiler is not able to see
the difference?
More information about the Digitalmars-d-learn
mailing list