1

My first time posting on here yay! So as the title says, the destructor crashes when I run the program. There is not one dynamically allocated element(it is possible to do it, but not until after the user fills up the array of ints) here's the code snippets:

IntSet::IntSet(int initial_capacity)
    {
        used = 0;
        capacity = initial_capacity;
        data = new int[initial_capacity];
    }
IntSet::~IntSet()
    {
        delete [] data;      
    }

private:
    int* data;
    int  capacity;
    int  used;

int main()
{
    {
        IntSet tccSet1 = is1;   // This is the assignment operator 
        IntSet tccSet2 = is2;   // is being used
        IntSet tccSet3 = is3;
        tccSet1.reset();
        tccSet2.reset();
        tccSet3.reset();
     //NOTE, this is where the scope of the objects above end. 
    //The destructor is called and the program crashes here.
    }     
    { 
        IntSet taoSet1;
        IntSet taoSet2;
        IntSet taoSet3;

        taoSet1 = is1;
        taoSet2 = is2;
        taoSet3 = is3;
    } 

return 0;
}

Some additional notes, when the first block of code in the main runs, no new dynamic allocation occurs. It appears to me as if the destructor is trying to delete an empty array or an array that tried to dynamically allocate with a size 0. Another option is that there was no dynamic allocation of memory. Thanks, Any help would be appreciated.

Pete Becker
  • 74,985
  • 8
  • 76
  • 165
  • Did you implement the assignment operator? – WhiZTiM Feb 14 '16 at 22:17
  • 2
    Should this really have been closed? It's not _exactly_ a duplicate, and simply posting one link hardly constitutes an answer that the OP can necessarily understand. – Mateen Ulhaq Feb 14 '16 at 22:37
  • @MateenUlhaq the top answer on the duplicate explains what OP needs to know. There's not much to be gained by repeating that same content when it's right there for the reading already – M.M Feb 15 '16 at 02:06

0 Answers0