使用三元运算符初始化参考变量? [英] Using ternary operator to initialize a reference variable?
本文介绍了使用三元运算符初始化参考变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将所有可维护性和读取问题搁置一旁,这些代码行是否会生成未定义的行为?
Putting all the maintainability and reading issues aside, can these lines of code generate undefined behavior?
float a = 0, b = 0;
float& x = some_condition()? a : b;
x = 5;
cout << a << ", " << b;
推荐答案
不,它不会在此代码中创建未定义的行为。您将根据条件将a或b的值更改为5。
No, it's just fine. It would not create undefined behavior in this code. You will just change value of a or b to 5, according to condition.
这篇关于使用三元运算符初始化参考变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文