Static function template
Daniel Kozák via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu May 7 03:36:04 PDT 2015
On Thu, 07 May 2015 10:19:42 +0000
Lemonfiend via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
wrote:
> Is it not possible to have a static function template with the
> same name as the non-static version?
>
> struct S
> {
> int i;
>
> auto foo(T)(int j) {
> i=j;
> }
>
> static auto foo(T)(int j) {
> S s;
> s.foo!T(j);
> return s;
> }
> }
>
> void main()
> {
> auto s = S.foo!bool(1);
> }
>
> Error: need 'this' for 'foo' of type '(int j)'
Btw. you can use s.foo even for static:
struct S
{
int i;
static auto foo(T)(int j) {
S s;
s.i = j;
return s;
}
}
void main()
{
auto s = S();
s = s.foo!bool(1);
writeln(s);
}
More information about the Digitalmars-d-learn
mailing list