primitive type operator overload

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Apr 20 11:03:25 PDT 2012


On Fri, Apr 20, 2012 at 07:12:41PM +0200, Mafi wrote:
> Am 20.04.2012 18:41, schrieb bearophile:
> >Dominic Jones:
> >
> >>I want to overload a primitive type operator so that I can do
> >>something like
> >>
> >>double a;
> >>myStruct b;
> >>writeln(a + b);
> >
> >You can't overload the operator of a primitive, but binary operators
> >come in left and right versions:
> ...
> >
> >Bye,
> >bearophile
> 
> Shouldn't a consequence of UFCS be that you can overload binary
> operators for primitives, as should global overloads (like in C++).

UFCS only kicks in if no matching method is found for the given type. So
UFCS can be used to provide "default" implementations for when an
operator is not defined for a given type, but the operator defined by
the type takes precedence over UFCS.


T

-- 
"How are you doing?" "Doing what?"


More information about the Digitalmars-d-learn mailing list