I'm trying to do some operator overloading, the function is supposed to add the values at index [i] of two vectors and place the result in the returning vector. The problem is I keep getting a vector out of range, I'm not sure where its going wrong.
this is the overloaded operator I'm working with (relatively new to these):
Looking at it again I see that I had an empty vector that I was trying to access, which you obviously cant do.
I changed it to this to push the sum of the two into the new vector but I still get the same problem.
1 2 3 4 5
float val;
for(unsignedint i = 0; i < size; i++){
val = a.at(i) + b.at(i);
temp.push_back(val);
}
I fixed it, I just wasn't taking everything in to account! As mentioned, when one stack was larger I was trying to add a value from one vector with an empty index from the other. I just threw in some if statements that checked for that and filled the rest of the smaller vector with zeros to match the others size if needed. Thanks for the help all!