I am having a problem in which my code is executing but then leads to a core dump, the capacity is 10. Here is the area of code that I believe is causing the problem, any tips?
Array& Array::operator+=(int value)
{
if (eltsInUse == capacity) {
cout << "\nElements in use: " << eltsInUse;
cout << "\nCapacity : " << capacity;
capacity++;
arrayCount++;
int* temp = new int[capacity];
for (int i = 0; i < capacity; i++) {
temp[i] = ptr[i];
}
} else {
//cout<<"\nElements in use: "<<eltsInUse;
cout << "\nCapacity : " << capacity;
ptr[eltsInUse] = value;
eltsInUse++;
cout << "\nElements in use: " << eltsInUse;
return *this;
}
}
User contributions licensed under CC BY-SA 3.0