Static function template

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 7 03:40:55 PDT 2015


On Thursday, May 07, 2015 10:19:42 Lemonfiend via Digitalmars-d-learn wrote:
> Is it not possible to have a static function template with the
> same name as the non-static version?

No. Unfortunately, you can't overload based on static. I believe that it
works if they're overloaded on parameters but not based on static. It's
probably in order to avoid function hijacking in cases like this:

S s;
s.foo();

since unfortunately, that call syntax works whether foo is static or not. I
think that it would be much better if you had to call it via the type and
that calling via an instance wouldn't be legal, but it is legal. And given
that fact, overloading based on static would arguably be a bad idea.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list