什么是“警告:不是所有控制路径都返回值”意思? (C ++) [英] What does "warning: not all control paths return a value" mean? (C++)

查看:930
本文介绍了什么是“警告:不是所有控制路径都返回值”意思? (C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到的确切警告是

warning C4715: 'hand::show' : not all control paths return a value

and hand :: show is

and hand::show is

std::ostream& hand::show(std::ostream& os) const
{
    if(side == left)
    {
    	return os<<display[0]<<display[1]<<display[2]<<display[3]<<display[4];
    }
    if(side == right)
    {
    	return os<<display[4]<<display[3]<<display[2]<<display[1]<<display[0];
    }
}

其中side是类型方向的变量

where side is a variable of type orientation

orientation{
    left = -1,
    right = 1
};

警告是什么意思,什么是最好的解决方案? p>

What does the warning mean, and what would be the best solution to get rid of it?

推荐答案

您的编译器不够聪明,不足以考虑 side left right ,因此它认为可能不执行return语句。当 side 既不是 left 也不是 right 不说要返回哪个值。

Your compiler isn't smart enough to take into account that the only two options for side are left and right, so it thinks it's possible for neither return statement to be executed. When side is neither left nor right, your function doesn't say which value to return.

这篇关于什么是“警告:不是所有控制路径都返回值”意思? (C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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