Jan 10, 2016 at 1:14am UTC
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 Jan 10, 2016 at 1:50am UTC
Jan 10, 2016 at 1:40am UTC
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 Jan 10, 2016 at 1:41am UTC
Jan 10, 2016 at 1:50am UTC
Im sorry my question was poorly worded. I changed it. What do you think of it now?
Jan 10, 2016 at 8:34am UTC
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 Jan 10, 2016 at 8:35am UTC