Orazio Contarino
Orazio Contarino

Reputation: 103

Binary Search Tree, allocating pointer to templated struct node

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

Answers (2)

Some programmer dude
Some programmer dude

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

Related Questions