DynamicIntArray & DynamicIntArray::operator=(const DynamicIntArray & right)
{
int * newArray = newint[right.capacity];
for (int i = 0; i < right.length; i++)
newArray[i] = right.array[i];
delete[] array;
array = newArray;
capacity = right.capacity;
length = right.length;
assert(this != &right);
assert(array != right.array);
return *this;
}
int DynamicIntArray::operator[](int index) const
{
if (index < 0 || index > length - 1)
{
cout << "Error. Index out of range." << endl;
return array[0];
}
return array[index];
}
Of course, the command does not seem to work because the overloaded assignment operator is supposed to work with objects of class DynamicIntArray. Can anyone give me a suggeston as to how I could write a working statement like this?