Hi I have a problem with deleting an object array. Whenever I start my code, it works just fine, but when I close, I am getting the error: 0xC0000005: Access violation reading location 0xcccccccc. The code goes like this:
I initialize an instance of an object and immediately make an empty array out of it.
Class* classObject[15];
Afterwards, I define the empty array in a for loop.
for(int i = 0; i < 15; i++){
classObject[i] = new Class();
}
When the application closes, the following code should delete the array out of memory.
for(int i = 0; i < 15; i++){
delete classObject[i];
}
Instead of successfully closing, I am getting the Access violation error. How can I fix this problem and where? Also, are there maybe other ways I could create objects in a for loop?
NULLor otherwise changed the pointers? Use of smart pointers (such asstd::shared_ptr) might have mitigated this problem.Class.