[D1] struct opEquals questions

qwerty qw at er.ty
Thu Mar 18 06:09:44 PDT 2010


bearophile Wrote:

> qwerty:
> > My opEquals takes an Vec2 and not a *Vec2, is this wrong?
> 
> It's OK. D1 docs say:
> Structs and unions (hereafter just called structs) can provide a member function:
> int opEquals(S s)
> or:
> int opEquals(S* s)
> 
> 
> > Why is return value of the rotate function compared and not the rotated struct literal?
> 
> You can add a  return this or return *this at the end of the rotate method.
If I return *this, I should also provide the *S version of opEquals? 
int opEquals(S* s) { return (i1 ==*s.i1 && i2 ==*s.i2); }

What happens with the return value if it isn't used?
Vec2(1,2).rotate(90);
I mean, where will the *this end up? Or will the compiler not return it at all?

> 
> Bye,
> bearophile



More information about the Digitalmars-d-learn mailing list