c++ - 在 switch 语句中使用运算符关键字

标签 c++ linux

因此,我尝试在此 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了解该语言的基本结构。

关于c++ - 在 switch 语句中使用运算符关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39863538/

相关文章:

c++ - 调整 cv::Mat 大小的最有效方法

c++ - 使用SFINAE计算不同元素的大小

c++ - 查找矩形外的网格起点

linux - 理解函数指针(信号系统调用)

linux - 在 Bash 脚本中,如何将变量添加到变量名中?

windows - Qt 工具栏按钮图标在 MinGW 构建后显示在 Windows 中,但在使用 g++ 构建后消失

c++ - 线程安全 std::vector push_back 和 reserve

c++ - 确定指令是否具有间接内存操作数

mysql - 在 Perl 中安装 DBI 模块面临问题

c++ - 表达式中的赋值?