Overloading static methods

Jacob Carlborg doob at me.com
Mon Aug 29 01:19:09 PDT 2011


I just got and idea, what about allowing to overload methods based on if 
they're static or not. This would allow the following code:

class Foo
{
     void bar () { writeln("bar"); }	
     static void bar () { writeln("static bar"); }
}

Foo.bar; // would print "static bar"
auto foo = new Foo;
foo.bar; // would print "bar"

When inside a class/struct there would be an ambiguity if both a static 
and a non-static method is present. To solve this one would always need 
to prefix the static method call with the class/struct name, i.e. 
"Foo.bar()". To call the instance method I see two options, either the 
method call needs to be prefixed with "this", i.e. "this.bar()" or all 
calls that are not prefixed would always call the instance method.

Thoughts?

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list