0

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(((

user3402740
  • 45
  • 1
  • 7

1 Answers1

3

Vector b(); doesn't create an object. It declares a function.

Vector b;
Vector a(1,1);

should work.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625