Using Defines as for Case

I am using a switch statement to determine the proper approach based on the value of a specific variable:

1
2
3
4
5
6
7
8
9
switch (mID) {
	case 0://Quit
	...
	break;

	case 1://Chat
	...
	break;
}



The only problem is, as soon as the number of cases scales to an unmanageable number, it becomes very difficult to keep track of everything. Also, eventually, I would like to change the values for each action (e.g. 0 to quit, change to 183 to quit).

So did the following, which doesn't work:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#define mQuit 0
#define mChat 1

...
...
...

switch (mID) {
	case mQuit://Quit
	...
	break;

	case mChat://Chat
	...
	break;
}
Define "not working". That should at least compile.
It doesn't compile. I do not remember the exact error.
Go try to compile it and get the error then...we can't help you without it.
Don't use "#define" unless absolutely required (e.g. include guards). Use an "enum". Defines don't care about any C++ rules. They are evil.
Topic archived. No new replies allowed.