博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
What does “warning: not all control paths return a value” mean? (C++)
阅读量:2443 次
发布时间:2019-05-10

本文共 791 字,大约阅读时间需要 2 分钟。

If switch case if cannot cover all cases, then the return value is undefined.

Even though orientation is an enum with only two values (right now), it can still have a different value for any of the following reasons:

  • In the future, you may change the header to include other values in the enum, so it's defensive programming to assume that this will happen (and your compiler is being nice and warning you now).
  • side might be uninitialized, so it could be neither left nor right
  • side might have been assigned another value via typecasting, e.g. *((int*)&side) = 2

Possible solutions include:

  • Replace the second if with an else as suggested by sth.
  • Change it to be:

    if(side == left) {
    return ...;} else if(side == right) {
    return ...;} else {
    ...handle error...}

转载地址:http://stiqb.baihongyu.com/

你可能感兴趣的文章
node.js运行js_Node.js运行时v8选项列表
查看>>
git教程_出色的Git教程的不完整列表
查看>>
Express,请求参数
查看>>
express发送文件_使用Express发送文件
查看>>
Object toString()方法
查看>>
调试JavaScript的权威指南
查看>>
我如何运行一些JavaScript代码段
查看>>
地理位置api_如何使用地理位置API
查看>>
数据结构设计 数据字典_Go数据结构:字典
查看>>
node_modules文件夹的大小不是问题。 这是一种特权
查看>>
dom 删除所有子元素_如何从DOM元素中删除所有子级
查看>>
html 打印样式控制_如何使用样式打印HTML
查看>>
gatsby_Next.js vs Gatsby vs create-react-app
查看>>
掌握React.Memo
查看>>
golang 延迟_了解Go中的延迟
查看>>
react 组件样式_如何设置React组件的样式
查看>>
node.js 模块_如何创建Node.js模块
查看>>
centos上安装git_如何在CentOS 8上安装Git
查看>>
在JavaScript中优化switch语句
查看>>
express 模板引擎_了解Express模板引擎
查看>>