Static operator overloads
Jarrett Billingsley
kb3ctd2 at yahoo.com
Tue Jun 5 06:22:07 PDT 2007
"Stuart Murray" <stuart.w.murray at fakey.spambot.avoiding.gmail.com> wrote in
message news:f42ted$23dg$1 at digitalmars.com...
> Hi everyone
> I'm a newbie to D and I've spent some time in the last few days messing
> around, seeing how things work.
>
> I noticed in a news posting that you can overload operators statically..
> i.e.
> Browsing through the documentation I didn't come across any mention that
> static member operators were supported. I was just wondering if they are
> in fact intentional?
It's legal. It's nice to have sometimes. It doesn't have the same purpose
as static/global operator overloads do in C++, though. It basically just
allows you to use the class/struct type as if it were a value.
> Also:
> I notice that having 2 member functions with the same signature, one
> static and one not, does not work (compiler claims it a conflicts). In
> particular, the above case, when the non-static opCmp is uncommented it
> will no longer compile.
>
> Is there any notes in the documentation to this effect? because I could
> not find any.
I don't know if it's mentioned anywhere, but since D allows you to access
static members through instances of a type, it doesn't surprise me that it's
illegal, because that would be ambiguous.
More information about the Digitalmars-d-learn
mailing list