Question on Template Specializing.
SteveGuo
steveguo at outlook.com
Tue Aug 6 22:10:12 PDT 2013
The following example can't be compiled.
// A.d
-------------------------------------
class A(T)
{
T a;
}
// main.d
-------------------------------------
import A;
int main(string param[])
{
A!(int) a;
return 0;
}
Compiler complains with this message "Error: template instance
A!(int) A is not a template declaration, it is a import"
So I read online documents, It says "TemplateInstantances are
always performed in the scope of where the TemplateDeclaration is
declared, with the addition of the template parameters being
declared as aliases for their deduced types."
So, I modified the code as the following
// A.d
-------------------------------------
class A(T)
{
T a;
}
alias A!(int) AInt;
// main.d
-------------------------------------
import A;
int main(string param[])
{
AInt a;
return 0;
}
This time it compiled successful.
But my question is:
If I am a library author, I write templates for my users, so
users can specialize the template with any types they defined. I
don't know what types they may define when I design the template,
so how can I specialize the template for them in my template
module?
More information about the Digitalmars-d
mailing list