gpt4 book ai didi

c++ - "Control may reach end of non-void function"警告

转载 作者:行者123 更新时间:2023-11-28 00:39:32 24 4
gpt4 key购买 nike

我在 Xcode 中运行一个 C++ 程序,遇到了“Control may reach end of non-void function”的警告。这是代码:

Node* search(Node* head, int x)
{
if(!head)
return NULL;
else if(x == head->key)
return head;
else if(x < head->key)
search(head->lchild, x);
else
search(head->rchild, x);
}

我在 Linux 中编译时得到了同样的警告,但得到了正确的结果。但在 Xcode 中,结果是错误的。顺便说一下,我在 Visual Studio 中得到了正确答案并且没有警告。

最佳答案

我想你的意思是返回递归调用的结果:

Node* search(Node* head, int x)
{
if(!head)
return NULL;
else if(x == head->key)
return head;
else if(x < head->key)
return search(head->lchild, x);
else
return search(head->rchild, x);
}

关于c++ - "Control may reach end of non-void function"警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19532286/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com