glibc detected *** ./testArray: free(): invalid next size (fast): 0x00000000

0

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;
    }
}
c++
asked on Stack Overflow Apr 17, 2020 by chern • edited Apr 17, 2020 by Miles Budnek

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0