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.