[D1] struct opEquals questions

qwerty qw at er.ty
Thu Mar 18 05:59:18 PDT 2010

Lars T. Kyllingstad Wrote:

> qwerty wrote:
> > In my unittest I tried to test out my rotate function.
> > assert(Vec2(1,2).rotate(90) == Vec(-2,1));
> > But I got these compile errors:
> > vector.d(156): Error: function vector.Vec.opEquals (Vec) does not match parameter types (void)
> > vector.d(156): Error: cannot implicitly convert expression (opCall(1,2).rotate(opCall(90))) of type void to Vec*
> > 
> > 2 questions:
> > My opEquals takes an Vec2 and not a *Vec2, is this wrong?
> > Why is return value of the rotate function compared and not the rotated struct literal?
> 2 problems:
> 1. You call the struct Vec some places and Vec2 others.
That's me trying to make the code more readable :(
All should be Vec2

> 2. My guess is that the compiler complains about Vec* because Vec is a 
> struct, not a class, and you have written 'new Vec' somewhere.  Am I right?
> If that is the case, remember that for structs, 'new' returns a pointer, 
> whereas for classes it returns a reference.
> -Lars

Sorry about my typos, bearophile luckily read right over them :)

More information about the Digitalmars-d-learn mailing list