Problem with switch

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
	enum numbers
	{
		LESS,
		HIGH,
		SAME
	};

	switch (numbers)
	{
	case '*':
		if (newOne == '-' || newOne == '+') return HIGH;
		if (newOne == '/') return SAME;
		break;
	case '/':
		if (newOne == '-' || newOne == '+') return HIGH;
		if (newOne == '*') return SAME;
		break;
	case '-':
		if (newOne == '*' || newOne == '/') return LESS;
		if (newOne == '+') return SAME;
		break;
	case '+':
		if (newOne == '*' || newOne == '/') return LESS;
		if (newOne == '-') return SAME;
	default:
    cout << "Hello :)";
	}


I'm trying to create a switch case to compare priorities of operators.
The error occurs at this line:
switch (numbers)
The bold and underlined parenthesis indicates where the red underlined error is.
The error is:
Expected a declarator in condition declaration

There are also other errors like:
Illegal case, Illegal break, and Illegal default


So, I'm assuming the entire switch code is wrong.
You're passing a type to your switch, when it expects an expression...

-Albatross
Last edited on
I'm not quite sure what you mean there.
Well... here. The tutorial could probably explain it much better than I can.
http://cplusplus.com/doc/tutorial/control/#switch

As you see, the switch expects an expression, but you're passing it a type (your enum).

-Albatross
Last edited on
Oh okay, now I see.
Thanks!
Topic archived. No new replies allowed.