Reputation: 39
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?
Upvotes: 0
Views: 281
Reputation: 66461
You do have more than one object in the array, but t
is not an array.
t
is a pointer to one BST, and the debugger displays it as such – the debugger has no idea that it's a pointer to the first element of an array.
If you want to view it as an array, you need to tell the debugger to do that.
You do this in the "Watch" window, and I think the syntax would be t,2
for displaying the first two elements.
Upvotes: 1