Hey guys, I'm having problems cleaning up a queue that is a dynamic array of pointers to objects. When I call my destructor, the program crashes. Here is my code..
Private section of class..
Code:
private:
OBJECT ** array; //declare pointer to pointer of OBJECT
int maxSize; //size of array
Constructor...
Code:
queue::queue( unsigned x ){
maxSize = x;
array = new OBJECT *[x]; //create dynamic array of size x
for ( int c = 0; c < x; c++ )
array[c] = NULL; //initialize each element of array to point to NULL
}
Destructor that crashes my program...
Code:
queue::~queue(){
for( int c = 0; c < maxSize; c++ ){//problem here
if( array[c] != NULL )
delete array[c]; //deletes OBJECT if there's one at that element
}
delete array; // deletes dynamic array
}
I'm a little new to dynamic arrays, any help would be appreciated. Thanks.