On Tuesday, 20 July 2021 at 06:20:34 UTC, Tejas wrote:
Why isn't it working by default?

Initially, I was trying to create the spaceship operator of C++, but we aren't allowed to create new operators, it seems. Then I just wanted to verify whether we can even overload an operator globally, but even that seems to be failing, atleast for me.

From the docs:

Operator overloading is accomplished by rewriting operators whose operands are class or struct objects into calls to specially named members.

https://dlang.org/spec/operatoroverloading.html

Note the word "members".

See also:

https://dlang.org/articles/rationale.html#why-no-global-operator-functions

Reply via email to