Invalid operands to binary expression while implementing vector [closed]

this[j] is hardly ever the right thing to do. It can only be correct, if *this happens to be a subobject within an array, and have at least j siblings after it. this[j] is equivalent to *(this + j). As you can see, it dereferences a pointer to jth sibling after *this.

I suspect, that you instead intended to access the elements of the buffer by calling Vector::operator[]. You’d do that by dereferencing the pointer first: (*this)[j].

Leave a Comment