Reputation: 103
I have a struct, and I'm trying to create an instance of a pointer to struct node.
here is my struct:
template<class T>
struct node{
T value;
struct node* lx;
struct node* rx;
struct node* f;
};
and here is what I'm trying to instance:
struct node<int>* n;
n<int> =new node;
How can I instance a pointer to struct node? I need it for a Binary Search Tree (insert function using template).
Upvotes: 2
Views: 92
Reputation: 409374
You are very close with that allocation. But you already declared n
to be a pointer to a node<int>
so the <int>
part is not needed for the variable. You do however need to specify the complete type in the new
operation, like
n = new node<int>;
Upvotes: 1
Reputation: 1
You are using the wrong syntax
n<int> =new node;
should be
n = new node<int>();
Upvotes: 1