Monday, May 24, 2010

I need to know how to make a destructor in c++ in which the variables are stored in a character array.?

1) If the array is just a regular "Static" character array, then you can't delete it or "destroy" it because it's not dynamic and does not exist on the heap.





ex. char array[100];








2) If the array is a dynamic character array, then you delete it as follows:





char* array = new char[100];


delete [ ] array;





3) If the array is a dynamic pointer-to-character array (a dynamic array whose elements are not character but pointers to characters), then you you delete is as follows:





char** array = new char[100];


for(int i =0; i %26lt; 100; i++)


{


delete array[i];


}


delete [ ] array;

local florist

No comments:

Post a Comment