Not allowed to globally overload operators?
Mike Parker
aldacron at gmail.com
Tue Jul 20 06:30:56 UTC 2021
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
More information about the Digitalmars-d-learn
mailing list