AVL 树最小和最大函数编译错误
我正在构建一个简单的 AVL 树,并从 GCC 收到以下编译器错误:
error: Expected constructor, destructor, or type conversion before '*' token
实现文件中的 min 和 max 函数声明都收到错误。
以下两个成员函数存在问题:
template <typename T>
tree_t<T>::node_t* tree_t<T>::min(node_t* t) const
{
node_t *temp = t;
while(temp->left != NULL)
{
temp = temp->left;
}
return temp;
}
template <typename T>
tree_t<T>::node_t* tree_t<T>::min(tree_t<T>::node_t*) const
{
node_t *temp = t;
while(temp->left != NULL)
{
temp = temp->left;
}
return temp;
}
以下是声明: public:
node_t* min(node_t* t) const;
node_t* max(node_t* ) const;
这是类和node_t结构声明
template <typename T>
class tree_t
{
private:
struct node_t
{
T data;
node_t *left;
node_t *right;
int height;
int bal;
node_t(const T& Element, node_t *lt, node_t *rt, int h = 0)
: data(Element), left(lt), right(rt), height(h) {};
};
node_t * root;
I am constructing a simple AVL tree and receive the following compiler error from GCC:
error: expected constructor, destructor, or type conversion before '*' token
Both the min and max function declarations in the implementation file receive the errors.
the following two member functions are at issue:
template <typename T>
tree_t<T>::node_t* tree_t<T>::min(node_t* t) const
{
node_t *temp = t;
while(temp->left != NULL)
{
temp = temp->left;
}
return temp;
}
template <typename T>
tree_t<T>::node_t* tree_t<T>::min(tree_t<T>::node_t*) const
{
node_t *temp = t;
while(temp->left != NULL)
{
temp = temp->left;
}
return temp;
}
Here is the declaration:
public:
node_t* min(node_t* t) const;
node_t* max(node_t* ) const;
Here is the class and the node_t struct declaration
template <typename T>
class tree_t
{
private:
struct node_t
{
T data;
node_t *left;
node_t *right;
int height;
int bal;
node_t(const T& Element, node_t *lt, node_t *rt, int h = 0)
: data(Element), left(lt), right(rt), height(h) {};
};
node_t * root;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法重现确切的错误。但是,以下是您可以关注的骨架。它不是最好的:-),但它是最接近的(即对原始代码进行最小的更改)。
I could not reproduce the exact error. However, following is a skeleton that you can follow. It is not the best :-), but it is the closest (i.e. making minimum changes to your original code) that compiles.