Array of size enum in C++

xrax

Senior member
Sep 17, 2005
341
0
0
Is there a way to make an array that has the same amount of elements as an enum typedef?
typedef enum

{
A, B, C

} Enum_Types;

typedef double Enum_Array[ ??? ];
 

BFG10K

Lifer
Aug 14, 2000
22,709
3,007
126
Use the last Enum value as your array size.

Enum_Array [C] in your case.
 
Sep 29, 2004
18,656
68
91
Originally posted by: BFG10K
Use the last Enum value as your array size.

Enum_Array [C] in your case.

A common practice is to have hte enums as follows:

{A,
B,
C,
MIN= A,
MAX = C
}

Then make your array size MAX.

TYhen if the enum list ever changes ... you can reassign MAX as desired and all your code should still work. Imagine if you used C in 100 places then decided C nees to be deleted ;)