operator overloading outside the type
Timon Gehr
timon.gehr at gmx.ch
Sat Mar 29 16:25:55 UTC 2025
On 3/29/25 17:07, Nick Treleaven wrote:
>
>> ```
>> import std.stdio;
>>
>> struct S{
>> void foo(){ writeln("member"); }
>> }
>>
>> struct T{
>> S s;
>> alias this=s;
>> }
>>
>> void foo(S s){ writeln("ufcs"); }
>
> I think `foo` should be `void foo(T t)`,
You are correct, it should be. This is closer to the original example.
> but it still prints "member" anyway :-)
Yes. UFCS never overrides a matching member function, no matter how well
the UFCS function matches. UFCS is not even attempted if a call can be
resolved via member function.
More information about the Digitalmars-d
mailing list