我正在浏览一个库,我看到了这个函数:
bool CCAPI::IsConnected() const
{
int state;
int res = CCAPIGetConnectionStatus(&state);
return (res == CCAPI_OK) && state;
}
具体来说,最后一行是什么意思?在我看来,它在使用 &&
运算符时返回了两个变量。那么这里发生了什么?
最佳答案
它将返回一个bool
,就像函数所说的那样。
运算符 &&
是逻辑 AND
,因此如果 res == CCAPI_OK
和 state != 0
那么它将返回 true
。在这种情况下,state
被隐式转换为 bool
用于 &&
操作。
关于使用 && 运算符的 C++ 函数返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34550459/