#include <iostream>
#include <string>
usingnamespace std;
struct Data
{
string key;
int* int_arr; //create a dynamically allocated array with this
bool* bool_arr; //create a dynamically allocated array with this
};
struct Node
{
Data* data; //pointer to data
Node* pLeft;
Node* pRight;
};
class BSTree
{
public:
~BSTree()
{
empty(root);
}
void empty(Node* &cur)
{
if(cur)
{
empty(cur->pLeft);
empty(cur->pRight);
delete cur;
cur = NULL; //<- is this necessary?
}
}
private:
Node* root;
};
My question is, will the BSTree class' destructor deallocate the memory allocated for the data pointer and the dynamically allocated arrays as well? If not, how can I deallocate them to prevent memory leaking