Not allowed to globally overload operators?
Tejas
notrealemail at gmail.com
Tue Jul 20 06:39:37 UTC 2021
On Tuesday, 20 July 2021 at 06:30:56 UTC, Mike Parker wrote:
> 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".
>
Ack. I remember reading the spec but have forgotten that detail
multiple times now.
> See also:
>
> https://dlang.org/articles/rationale.html#why-no-global-operator-functions
Well, this is new. **sigh** Guess I'll have to find another way
to implement spaceship then. I don't disagree with the rationale,
but it is a little inconvenient in my case.
More information about the Digitalmars-d-learn
mailing list