2016-10-05 104 views
-6

所以我试图在这个switch语句中使用“operator”关键字,但是当我这样做时,我得到错误“error:expected-type specifier before→token operator:” I数字关键字没有出现任何错误。有任何想法吗?在switch语句中使用运算符关键字

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; 
      } 
     } 
    } 
+0

你期待它做什么? – immibis

+0

我尝试在我的婚礼蛋糕中使用“炸药”成分,但是当我这样做时,烤箱出现故障。我对“木屑”成分没有任何问题。 –

+0

@KerrekSB你期待它做什么? – immibis

回答

0

在C++中,运算符是一个仅用于运算符重载的关键字。不幸的是,这在任何其他情况下都是非法的。

代码中定义的“数字”在哪里?

+0

我没有定义它,但是当我使用它们时,它们都显示为与所有其他保留字一样的黄色。对不起,如果我问的似乎很愚蠢。 – Drogo

2

所呈现的代码在语法上是无效的:

  • 它缺乏case关键字为switch标签。

  • 它使用关键字operator作为名称。

重新

I am not getting any error for the digit keyword.

&hellip;这不是关键字。

Google C++关键字。让自己a decent C++ textbook了解该语言的基本结构。