&是什么QUOT;控制到达非void函数&QUOT结束;意思? [英] What does "control reaches end of non-void function" mean?

查看:154
本文介绍了&是什么QUOT;控制到达非void函数&QUOT结束;意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经对这个二进制搜索算法得到奇怪的编译器错误。我得到的控制到达非void函数结束的警告。这是什么意思?

  INT二进制(INT VAL,诠释整理[],INT低,诠释高){
    INT中旬=(低+高)/ 2;    如果(高<低)
        返回-1;    如果(VAL<整理​​[MID])
        返回二进制(VAL,排序,低,中-1);    否则,如果(VAL>分类[MID])
        返回二进制(VAL,整理,中期+ 1,高);    否则,如果(VAL ==排序[MID])
        返回中旬;
}


解决方案

编译器不能从code告诉我们函数永远不会到达终点,仍然返回值。为了说清楚,替换最后一个否则,如果(...)只有其他

I've been getting strange compiler errors on this binary search algorithm. I get a warning that control reaches end of non-void function. What does this mean?

int binary(int val, int sorted[], int low, int high) {
    int mid = (low+high)/2;

    if(high < low)
        return -1;

    if(val < sorted[mid])
        return binary(val, sorted, low, mid-1);

    else if(val > sorted[mid])
        return binary(val, sorted, mid+1, high);

    else if(val == sorted[mid])
        return mid;
}

解决方案

The compiler cannot tell from that code if the function will ever reach the end and still return something. To make that clear, replace the last else if(...) with just else.

这篇关于&是什么QUOT;控制到达非void函数&QUOT结束;意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆