Dynamic Issue

Hi, I am getting an "aborted(core dumped)" when I include the destructor. Could someone help understand what is wrong?
1
2
3
4
5
6
7
const int Size = 100;
class test
{
  private:
   int * array;
};


1
2
3
4
5
6
7
//Constr
test::test()
{
    array = new int [Size];
    for(int i = 0; i < Size; i++)
        array[i] = -1;
}


1
2
3
4
5
6
7
//destructor
test::~test()
{
   for(int i = 0; i < Size; i++)
   delete [] array;
}
You don't need to use for loop inside destructor. Your array is one dimensional. Just
delete array; is enough
You're trying to deallocate memory "Size" times. After the first call to delete the memory location will become invalid and generate an error if you try to use it again
Okay, I see I ran the code in the codeblocks compiler and it worked with no errors. Anyway Thanks guys
Topic archived. No new replies allowed.