The last couple of days I've been trying to figure out how to make a dynamically allocated array of this class I made. One of them includes another class I made
Here are the classes:
template<typename T>
class BST // a binary search tree class
{
private:
Node<T> * root;
int size;
public:
BST()
{
root = NULL;
size = 0;
}
/*void * BST::operator new[](size_t a) //tried it both with the "BST::" and without
{
void * p = malloc(a);//24
return p;
}*/
//there are more functions that i cut out
}
and
template <typename T>
class Node //a node for a binary search tree
{
public:
int key;
T data;
Node * left;
Node * right;
Node * parent;
//public:
Node<T>()
{
key = NULL;
data = NULL;
left = NULL;
right = NULL;
parent = NULL;
}
//more stuff below this but it's just getting and setting the data
}
in main() i'll try to make an array of BST objects with this line:
BST<char> * t = new BST<char>[ n ]; //the user will give the value for int n
The issue is that it only makes one BST object when running. I've done some research and experimented with overloading the new[] operator which did absolutely nothing.
Can someone please explain what the proper way to do this would be?
nobjects. Are you sayingn == 1?