Is there a built in function or a way to query the size of an emun typedef?
typedef开发者_如何学运维 enum difficultyTypes {
kEasy,
kMedium,
kHard
} difficultyType;
I would like a way to query and have it ( in this case ) return 3. I could even deal with it returning 2 as the highest value ( 0,1,2 ).
Or am I forced to use another int variable that I statically set when I create the enum?
You may want to reference this post.
To clarify his answer, looking at your example you could do the following
typedef enum difficultyTypes {
kEasy,
kMedium,
kHard,
kCount
} difficultyType;
kEasy would be 0, kMedium is 1, kHard is 2, and kCount is 3, which is the number of elements you have minus itself.
精彩评论