-7

So I am trying to use the "operator" keyword in this switch statement but when I do I get the error "error: expected type-specifier before â:â token operator:" I am not getting any error for the digit keyword. Any ideas?

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;
          }
      }
  }
Drogo
  • 1
  • 2

2 Answers2

2

The code as presented is syntactically invalid:

  • It lacks the case keyword for the switch labels.

  • It uses the keyword operator as a name.

Re

I am not getting any error for the digit keyword.

… that's not a keyword.

Google C++ keywords. Get yourself a decent C++ textbook to learn about the basic constructs of the language.

Community
  • 1
  • 1
Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331
0

In C++, operator is a keyword used only for operator overloading. Unfortunately, that makes it illegal to use in any other case.

Where is "digit" defined in your code?

NoSeatbelts
  • 13
  • 1
  • 3
  • I didnt define it but both show up yellow like all the other reserved words when I use them. Sorry if what I'm asking seems stupid. – Drogo Oct 05 '16 at 00:22