Template instantiation and string vs const char[]
Jason den Dulk via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Sep 2 22:18:40 PDT 2014
I have this piece of code:
template somet(R...) {
static if (R.length)
{
string somet = "[\n"~R[0]~"\n" ~ somet!(R[1..R.length]) ~
"]\n";
}
else
string somet = "";
}
void main()
{
writeln(somet!("name","tame"));
writeln(somet!"name");
}
When I compile it, it generates the error message "static
variable somet cannot be read at compile time". When I replace
'string' with 'const char[]', it works.
Can anyone explain why this happens?
Thanks.
Regards
More information about the Digitalmars-d-learn
mailing list