I have a dynamically allocated char**
array as a private member in one of my classes.
The first allocation occurs according to number of words
client_interests = new char* [n];
Later each index of the array is allocated according to length of the word + 1
char[i] = new char [strlen(word)+1];
Would this be the proper way of deallocating the memory of this member (the classes dtor is calling this function)?
void Client::deallocate()
{
int i;
for (i = 0; i < n; i ++) //loops through each word
{
delete [] client_interests[i]; //each word is an array of characters, hence delete [] is used
}
delete [] client_interests; //deallocating the pointer
client_interests = NULL;
}
Thaks!