错误:控制到达非无效函数的结尾[-Werror = return-type]} ^ [英] error: control reaches end of non-void function [-Werror=return-type] } ^

查看:68
本文介绍了错误:控制到达非无效函数的结尾[-Werror = return-type]} ^的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题基本上是要根据给定的'n'个数字生成算术表达式,并且该表达式应可被101整除.我们只能使用+,-,*运算符,并且表达式保持关联.

The problem is basically about to generate a arithmetic expression from a given 'n' numbers , and the expression should be divisible by 101. we can only have +,-,* operators and expression is left associative.

我在上尝试了所有可用的解决方案,这些解决方案已在堆栈溢出中提及,例如使用else等关闭表达式

I have tried all the available solution on , that are already mentioned on stack overflow, like closing the expressions with else and many more

bool calci(int a[],int n,int sum,int pos,char operato[],deque<int>&q,deque<char>&qc)
{

    if(sum%101==0)
    {   //cout<<"sum:"<<sum<<endl;
        return true;
    }

    else if(pos==n)
        {return false;}
    else
    {
    for(int k=0;k<3;k++)
    {  // cout<<"here for "<<a[pos]<<endl;
        sum=addto(sum,a[pos],operato[k]);
        qc.push_back(operato[k]);
        q.push_back(a[pos]);
        bool kyaagesemila=calci(a,n,sum,pos+1,operato,q,qc);
        if(kyaagesemila)
            {
                return true;
            }
        sum=removefrom(sum,a[pos],operato[k]);
        qc.pop_back();
        q.pop_back();
    }
    }
}

我遇到编译错误

solution.cc:53:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^
cc1plus: some warnings being treated as errors```

推荐答案

错误消息很清楚.该函数的返回类型为 bool ,但在某些执行路径中不返回任何内容.

The error message is clear enough. The function has the return type bool but returns nothing in some execution paths.

最后的else语句中的带有布尔表达式的return语句在哪里?

Where is there in the last else statement a return statement with a boolean expression?

或者您需要重写最后的else语句,以使其在循环外返回布尔表达式.

Or you need to rewrite the last else statement such a way that it would return a boolean expression outside the loop.

例如,在循环之后,您可以添加语句

For example after the loop you can add statement

return false;

P.S.使用英语单词作为变量标识符.

P.S. Use English words as variable identifiers.

这篇关于错误:控制到达非无效函数的结尾[-Werror = return-type]} ^的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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