Issue
I'm implementing template binary tree in cpp with eclipse and I have trouble.
template <class T> struct node{
T data;
struct node *left;
struct node *rigth;
};
template<class T> node* newnode(T d) {
struct node *ret = new(struct node());
ret->left = NULL; //err here
ret->right = NULL;//err here
ret->data = d; //err here
return ret;
}
I'm getting error "Field 'left' couldn't be resolved.". What's wrong? Thanks in advance.
Solution
template <class T> struct node {
T data;
struct node<T> *left;
struct node<T> *rigth;
};
template<class T> node<T>* newnode(T d) {
struct node<T> *ret = new struct node<T>();
ret->left = NULL;
ret->right = NULL;
ret->data = d;
return ret;
}
Answered By - Alex F
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.