how to instantiate a class template on the heap

I have a template class called BST and BSTNode:

template<typename Data>
class BST
{
//code
}

template<typename Data>
class BSTNode
{
//code
}

How do I instantiate BSTNode on the heap within the BST class? If its not this:

BSTNode<Data>* node=new BSTNode<Data>;

Then what is it?
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
template<typename Data>
class BST
{
Data u;
}

BST<int>* node=new BST<int>;
node->u // <-- is type of int


BST<double>* node2=new BST<double>;
node2->u // <-- is type of double 
Last edited on
Im sorry my question was poorly worded. I changed it. What do you think of it now?
Armonsafai, yes, you do it the way you said.

1
2
3
4
5
6
7
8
9
template<typename Data>
class BST
{
	void insideTheBSTClass()
	{
		BSTNode<Data>* node=new BSTNode<Data>;
		delete node;
	}
};
Last edited on
Topic archived. No new replies allowed.