gpt4 book ai didi

c++ - "warning: operation of ... may be undefined"用于三元运算——不是 if/else block

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:22:07 26 4
gpt4 key购买 nike

<分区>

这是我的代码:

int main() {
static int test = 0;
const int anotherInt = 1;
test = anotherInt > test ? test++ : 0;
if (anotherInt > test)
test++;
else
test = 0;
return 0;
}

这是我构建它时产生的警告:

../main.cpp:15:40: warning: operation on ‘test’ may be undefined [-Wsequence-point]
test= anotherInt>test ? test++ : 0;
^

为什么 C++ 在三元运算时给我警告,而不是常规的 if..else 语句?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com