原因是在switch 中有初始化的工作。
在switch 語句中不可以有定義部分。如果有定義,如初始化的時候,必須把定義部分用{ } 括起來。
例如:
這段代碼 case 後的代碼增加了一個括號,括起來,沒有這對括號就會報錯
case binaryop:
{ // 增加的括號
bool end_right=false; // 標誌操作符的右操作數是否結束
do
{
if(delayed_operations.empty())end_right=true;
else
{
prior=delayed_operations.top();
if(prior.Kind()==leftparen)end_right=true;
else if(prior.Priority()<current.Priority())end_right=true;
else if(current.Priority()==6)end_right=true;
else answer.Put_token(prior);
if(!end_right) delayed_operations.pop();
}
}while (!end_right);
delayed_operations.push(current);
break;
} // 增加的括號
default: cout<<" 你的輸入格式可能不正確!"<<endl;break;