Static function template

Daniel Kozák via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 7 03:32:12 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)'

It is not. You can't even have same name for field and method:

struct S
{
    int s;
    void s() { do_something(); }
}

test.d(8): Error: function test.S.s conflicts with variable test.S.s at
test.d(7)

And this make sense


More information about the Digitalmars-d-learn mailing list