I’m getting errors when trying to add two data type SmartArrays together. I think the error is within the assignment operator but I can’t seem to figure out the problem. Below are two functions from the templated class SmartArray. When attempting to run unit tests, I get the errors at the bottom of the page.
Is there something I’m missing? Thank you in advance.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
SmartArray& operator= (const SmartArray& right){
if(this == right){
return this;
}
delete[] this->things;
things = new T[SMART_ARRAY_CAPACITY];
for (unsigned int i = 0; i < right.size(); i++){
things[i] = right[i];
}
}
SmartArray operator+ (const SmartArray& right){
SmartArray ret;
for (unsigned int i = 0; i++; i < right.size()){
ret[i] = right[i];
}
if ((right.size() + s) < SMART_ARRAY_CAPACITY){
for (unsigned int i = 0; i < right.size(); i++){
ret[s+i] = right[i];
}
}
else{
throw logic_error("Not enough room in array");
}
return ret;
}
|
I also tried it as ret = right without the loop in the + function, but that didn’t work either.
The errors I receive are below:
In file included from SmartArray_hw_test.h:4:0,
from testrunner.cpp:23:
SmartArray.h: In instantiation of ‘SmartArray<T> SmartArray<T>::operator+(const SmartArray<T>&) [with T = int]’:
SmartArray_hw_test.h:89:5: required from here
SmartArray.h:122:16: error: lvalue required as left operand of assignment
ret[i] = right[i];
^
SmartArray.h:126:20: error: lvalue required as left operand of assignment
ret[s+i] = right[i];
^
make: *** [testrunner] Error 1