为了账号安全,请及时绑定邮箱和手机立即绑定

函数缺少返回值,运行时行为

函数缺少返回值,运行时行为

C++
杨__羊羊 2020-02-02 14:11:00
正如预期的那样,编译器(VisualStudio 2008)将发出警告警告C4715:“ doSomethingWith”:并非所有控制路径都返回值编译以下代码时:int doSomethingWith(int value){    int returnValue = 3;    bool condition = false;    if(condition)        // returnValue += value; // DOH    return returnValue;}int main(int argc, char* argv[]){    int foo = 10;    int result = doSomethingWith(foo);    return 0;}但是程序运行正常。函数doSomethingWith()的返回值为0。是只是未定义的行为,还是在运行时确定/如何计算结果值有特定规则。非POD数据类型作为返回值会怎样?
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 485 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信