D
DamonChong
Hi,
I am new to c++. I recently spend an enormous among of time
troubleshooting a seeminly innocuous piece of code. Although I narrow
down this piece of code as the culprit but I don't understand why. Can
some guru help to enlighten me? Thank you.
// I created an array of pointers to object pointers:
Object ** obs = new Object * [9];
// After that I populate this array:
for(int i=0; i<9; i++){
obs = new Object(i);
}
// After using them i deleted the array:
for(int i=0; i<9; i++){
delete obs;
}
delete [] obs;
delete obs; // this is the problem, during execution the program
hanged.
Apparently, the above caused undefined behaviour. But I don't know why
i shouldn't do that. Thanks again for any sharing!
Cheers,
Damon
I am new to c++. I recently spend an enormous among of time
troubleshooting a seeminly innocuous piece of code. Although I narrow
down this piece of code as the culprit but I don't understand why. Can
some guru help to enlighten me? Thank you.
// I created an array of pointers to object pointers:
Object ** obs = new Object * [9];
// After that I populate this array:
for(int i=0; i<9; i++){
obs = new Object(i);
}
// After using them i deleted the array:
for(int i=0; i<9; i++){
delete obs;
}
delete [] obs;
delete obs; // this is the problem, during execution the program
hanged.
Apparently, the above caused undefined behaviour. But I don't know why
i shouldn't do that. Thanks again for any sharing!
Cheers,
Damon