The advantages of enum
show up when you have a long list of things you want to map into numbers, and you want to be able to insert something in the middle of that list. For example, you have:
pears 0 apples 1 oranges 2 grapes 3 peaches 4 apricots 5
Now you want to put tangerines
after oranges
. With #define
s, you’d have to redefine the numbers of grapes
, peaches
, and apricots
. Using enum, it would happen automatically. Yes, this is a contrived example, but hopefully it gives you the idea.