[英]C++ trivial function: return value type doesn't match the function return type: ternary operator
I cannot understand why would Visual Studio Intellisense complain.我不明白为什么 Visual Studio Intellisense 会抱怨。 In the code:在代码中:
int absolute_value(int x) {
return x > 0 ? x : - x;
}
It underlines x
in return x
with the message: return value type doesn't match the function return type.它在return x
x
加下划线,并带有以下消息:返回值类型与 function 返回类型不匹配。
My environment is win10, vs2022.我的环境是win10,vs2022。 I tested the code you posted, the code works fine, I suggest you repair your Visual Studio or download it again.我测试了您发布的代码,代码运行良好,建议您修复您的 Visual Studio 或重新下载。
#include<iostream>
using namespace std;
int absolute_value(int x) {
return x > 0 ? x : -x;
}
int main()
{
cout << absolute_value(-6);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.