UFCS and overloading

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Apr 6 10:53:13 PDT 2015


On 4/6/15 12:23 PM, Szymon Gatner wrote:
> Hi,
>
> I am surprised that this doesn't work:
>
> class Foo
> {
>    void bar(string) {}
> }
>
> void bar(Foo foo, int i)
> {
> }
>
> auto foo = new Foo();
> foo.bar(123); // <=== error
>
> causing compilation error:
>
> main.d(24): Error: function main.Foo.bar (string _param_0) is not
> callable using argument types (int)
>
> does UFCS now work with method overloading? I know it is not a syntax
> error because changing the name of int version of bar to bar2 and
> calling foo.bar2(123) works fine.

You can't do this. UFCS cannot add overloads, it can only add whole 
overload sets (if not already present).

-Steve


More information about the Digitalmars-d-learn mailing list