[D1] struct opEquals questions
Lars T. Kyllingstad
public at kyllingen.NOSPAMnet
Thu Mar 18 05:40:00 PDT 2010
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.
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
More information about the Digitalmars-d-learn
mailing list