I the next simple constructor:
Vector(double x=0, double y=0) : x(x), y(y) {}
void operator+=(const Vector& other) {
this->x += other.x;
this->y += other.y;
}
But when I call it like this
Vector b();
Vector a(1,1);
and try to do a += b; compiler gives me a lot of errors saying that no operators exist. However when I do like this: Vector b(0,0); or Vector b(0); everything works(((
+=? If you want the operator, you have to overload it. That has nothing to do with constructors. But as a side note, you should make this constructor explicit, or simple numbers will implicitly convert to vectors as x coordinates.this->is not necessarythisin such cases to be clear which of the two objects is being used.