我想在C++的switch/case语句中使用const int数组.可能吗?到目前为止,我尝试过类似的东西:
int main()
{
int const tab[3] = {1,2,3};
int value(2);
switch(value)
{
case tab[1]:
cout << "result is: " << tab[0]<< endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
然而,编译器一直告诉我:
.../main.cpp|11|error: the value of ‘tab’ is not usable in a constant expression
Run Code Online (Sandbox Code Playgroud)
我把我的数组声明为"int const",这还不够吗?