为什么下面的代码会产生警告:“警告:开关条件具有布尔值”
#include <iostream>
using namespace std;
int main() {
const bool yes = true;
switch (yes) {
case true: cout << "sure" << endl; break;
case false: cout << "nope" << endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
switch 语句只接受数字和字符吗?