Unable to instantiate template with same name as function
Shriramana Sharma via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Mar 4 18:28:17 PST 2016
ag0aep6g wrote:
> On 03.03.2016 07:12, Shriramana Sharma wrote:
>> string ta(string s) { return s ~ "1"; }
>> template ta(string s) { enum ta = ta(s); }
>
> In `ta(s)` here, `ta` is the enum itself again. It's similar to `int x =
> x;`. Can't do that, of course.
>
> Add a leading dot to refer to the module level `ta` symbols instead:
> `enum ta = .ta(s);`.
Wonderful! So it's just a scope issue and not a "can't do that" issue!
Although it would seem that the compiler 'should' be able to identify a
different kind of ta, I can't expect too much of it and the D compiler is
much more powerful syntax-wise than other language compilers.
I confirm that the following outputs "s1" as expected with the function call
inside the template having the dot added in front:
string ta(string s) { return s ~ "1"; }
template ta(string s) { enum ta = .ta(s); }
void main()
{
import std.stdio;
writeln(ta!"s");
}
--
Shriramana Sharma, Penguin #395953
More information about the Digitalmars-d-learn
mailing list