我正在使用eclipse在cpp中实现模板二叉树,我遇到了麻烦。
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;
}
我收到错误“Field'left'无法解决。”怎么了?提前谢谢。
答案 0 :(得分:2)
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; }