How can I explicitly reference this template member?
Template members can be indirectly referred to if they are the only member of the template and if they share the template name:
template foo(int number)
{
immutable int foo = number;
}
void main()
{
writeln(foo!(123)); // Okay.
}
But what if I want to explicitly reference an element?
writeln(foo!(123).foo); // Error: attempts to access the foo property of int.
I have no good reason for this, but I feel it is possible.
+3
source to share
2 answers
Epident templates are replaced with their values when used. So, regarding the compiler, write
writeln(foo!(123).foo);
basically the same as the entry
writeln(123.foo);
And this is not legal. This line will lead to the exact same error you are getting. You shouldn't be able to access members of the template of the same name. They are intentionally opaque.
+7
source to share