声明与void不兼容

  • 本文关键字:不兼容 void 声明 c++
  • 更新时间 :
  • 英文 :


嗨,我得到一个错误说声明是不兼容的void。我真的不知道如何解决这个问题,我会感激一些帮助。这是用于运行Avl树的程序。我还有。h文件。

template <typename Comparable>
void AvlTree<Comparable>::rightRotate(AvlNode *&y) const
{
AvlNode *x = y->left;
AvlNode *x2 = x->right;
x->right = y;
y->left = x2;
y->height = max(height(y->left),
height(y->right)) + 1;
x->height = max(height(x->left),
height(x->right)) + 1;
return x;
}
template <typename Comparable>
void AvlTree<Comparable>::leftRotate(AvlNode *&x) const
{
AvlNode* y = x->right;
AvlNode x2 = y->left;
y->left = x;
x->right = x2;
y->height = max(height(x->left),
height(x->right)) + 1;
x->height = max(height(y->left),
height(y->right)) + 1;
return x;
}
template <typename Comparable>
void AvlTree<Comparable>::insert(const Comparable &x, AvlNode *&t) const
{
if(node == NULL){
return (newNode(t));
}
if(key < x->t){
x->left = insert(x->left, t)
}
}

你试图在一个void声明的方法中返回一些东西:

template <typename Comparable>
void AvlTree<Comparable>::insert(const Comparable &x, AvlNode *&t) const
{
if(node == NULL){
// you cant return something in a void method
return (newNode(t));
}
if(key < x->t){
x->left = insert(x->left, t)
}
}

最新更新