So i have an array elements and it is declared like this:
Loans ** elements;
elements = new Loans*[initial_size];
where initial_size = 4
I have a remove some element method that checks if it is a good time to shrink the array (ie there is more then twice the amount of space for the amount of elements)
Code:
index--;
if(index < capacity/2) { //shrink the container
cout << "shrinking\n";
Loans ** temp = elements;
elements = new Loans*[capacity/2];
for(int i=0; i<index; i++) elements = temp;
capacity = capacity/2;
delete [] temp;
}
It always crashed on this line:
elements = new Loans*[capacity/2];
Whats the problem??
Thanks for any help.
Loans ** elements;
elements = new Loans*[initial_size];
where initial_size = 4
I have a remove some element method that checks if it is a good time to shrink the array (ie there is more then twice the amount of space for the amount of elements)
Code:
index--;
if(index < capacity/2) { //shrink the container
cout << "shrinking\n";
Loans ** temp = elements;
elements = new Loans*[capacity/2];
for(int i=0; i<index; i++) elements = temp;
capacity = capacity/2;
delete [] temp;
}
It always crashed on this line:
elements = new Loans*[capacity/2];
Whats the problem??
Thanks for any help.