有人可以给我一个为什么我在使用三元运算符时不能返回表达式的原因吗?
while( root != nullptr )
{
if( current->data > v ) {
( current->left == nullptr ) ? return false : current = current->left;
} else if( current->data < v ) {
current->right == nullptr ? return false : current = current->right;
} else if( current->data == v ) {
return true;
}
}
return false;
为什么我尝试返回 false 时会出错?我知道我可以这样做:
return ( ( 0 == 1 ) ? 0 : 1 );
但是当只是试图从一个表达式返回时,编译器有什么问题呢?