警告“控制可能到达非空函数的结尾" [英] Warning of "Control may reach end of non-void function"
本文介绍了警告“控制可能到达非空函数的结尾"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 Xcode 中运行了一个 C++ 程序,遇到了控件可能会到达非空函数的结尾"的警告.代码如下:
I ran a C++ program in Xcode, and encountered a warning of "Control may reach end of non-void function". Here is the code:
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 中得到了正确的答案并且没有警告.
I got the same warning when compiling it in Linux, but got the correct result. But in Xcode, the result was wrong. By the way, I got the correct answer and no warning in Visual Studio.
推荐答案
我想你的意思是返回递归调用的结果:
I think you mean to return the result of the recursive calls:
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);
}
这篇关于警告“控制可能到达非空函数的结尾"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文