Trouble deleting variables

Is anyone else having their programs crash once it comes across a delete statement?

for example, i am implementing a dynamic array manually and when I have to resize the array I use a temp variable and then delete it when done:

void mainScene::reSizeAgentArray(){
agentArrCt *= 2;
persAgent **temp = new persAgent *[agentArrCt];
for(int i = 0; i < agentCt; i++){
temp[i] = arrAgents[i];
}
arrAgents = temp;

for(int i = 0; i < agentArrCt; i++){
delete temp[i];
}

return;
}

thoughts?

use std::vector.

  
    for(int i = 0; i < agentArrCt; i++){  
        delete temp;  
    }  

here you are deleting temp several times so it’s going to crash, also it’s usually easier to use vectors since they auto delete once the function ends:

  
void mainScene::reSizeAgentArray(){  
    agentArrCt *= 2;  
    vector<persAgent *> temp(agentArrCt]);  
    for(int i = 0; i < agentCt; i++){  
        temp[i] = arrAgents;  
    }  
...  
 }  

sorry, i miss wrote the code.

i mistakingly wrote:

  
for(int i = 0; i < agentArrCt; i++){  
    delete temp;  
}  

when what was actually in the code (and still failed):

  
for(int i = 0; i < agentArrCt; i++){  
    delete temp[i];  
}  

temp is a pointer to an array of pointers, so each pointer which temp points to needs to be deleted individually. At least thats how it’s supposed to go.

and i know i can use vectors but i started with manual dynamic arrays and now i’m too deep in it to switch.