因此,我尝试在此 switch 语句中使用“operator”关键字,但是当我这样做时,我收到错误“error:expected type-specifier before â:â token operator:” 我没有收到任何关于数字关键字的错误。有什么想法吗?
for (i=0; i < pf.length(); i++)
{
int opn1;
int opn2;
int result;
char token = pf[i];
switch (token)
{
digit:
{
chast.push(token); break;
}
operator:
{
opn2 = chast.top();
chast.pop();
opn1 = chast.top();
chast.pop();
result = evaluate(opn1, token, opn2);
chast.push(result);
break;
}
}
}
请您参考如下方法:
所提供的代码在语法上无效:
它缺少
switch
标签的case
关键字。它使用关键字
operator
作为名称。
回复
” I am not getting any error for the digit keyword.
...这不是关键字。
Google C++ 关键字。获取自己a decent C++ textbook了解该语言的基本结构。