ala*_*ehu 1 c++ conditional operator-keyword
!isalpha( str[first] ) ? ( return isPalindrome( str, ++first, last ) ) : return isPalindrome( str, first, --last ) ;
Run Code Online (Sandbox Code Playgroud)
我收到语法错误.
这是不允许的,因为return在表达式中不允许; 它只允许在声明的顶层.(任何表达式都可以用作语句,但反之则不然.)你可以这样写:
return !isalpha(str[first])
? isPalindrome(str, ++first, last)
: isPalindrome(str, first, --last);
Run Code Online (Sandbox Code Playgroud)
或这个:
if (!isalpha( str[first] )) {
return isPalindrome( str, ++first, last );
} else {
return isPalindrome( str, first, --last );
}
Run Code Online (Sandbox Code Playgroud)