I'm just wondering if there's now a more accepted way to define a set of values than #define.
Say I have the following:
#define C_CMD1 1
#define C_CMD2 2
#define C_CMD3 3
Is there a more accepted way of doing this now that doesn't require #defines, and preferably is restricted in scope so the same name can be used in different classes with different values associated with them? I thought of CONST Variables but it seems like a waste of ram.
Using consts would be the only other way to do it, AFAIK.
I wouldn't say using const variables is a waste of RAM. Think about how much sapce an int takes (usually 4 bytes, sometimes 2 or 8) compared to the amount of memory you have access to (several megabytes).
The type safety, and additional ease of debugging actual variables as opposed to #defines is well worth a few bytes per variable.
And there's the fact that most modern compilers automatically substitute const non-user-defined variables with literals. So there's no wasted memory.
I know this doesn't cover user-defined classes; but then again, neither does #define.
The prefered way to define constants in C++ is using the keyword const.