C++ 返回一个赋值? [英] C++ returning an assignment?
本文介绍了C++ 返回一个赋值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 C++ 中,函数返回赋值是什么意思?例如
In C++ what does it mean when a function returns an assignment? e.g.
int a = ...;
int b = ...;
int some_function(p)
{
return a = b;
}
推荐答案
在这种情况下它执行赋值,然后返回b
.
In this case it performs the assignment, then returns b
.
这类东西可能会被编译器标记为一个无意的错误,通常你的意思是 a == b
,所以你可能需要处理它.将其作为单独的一行进行,可以清楚地表明这是有意为之.
This sort of stuff might get flagged by the compiler as an inadvertent bug, usually you'd mean a == b
, so you may need to deal with that. Doing it as a separate line makes it clear it's intentional.
这篇关于C++ 返回一个赋值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文