• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1745
  • Last Modified:

Get number of element in an enum

I need to determine the number of elements in an enumaration.
0
zordes
Asked:
zordes
  • 2
  • 2
1 Solution
 
johnnash1180Commented:
enum enumDigits {ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE};

int totalDigits = enumDigits.values().length;

John Nash.
0
 
zordesAuthor Commented:
Sorry
I have selected the wrong zone. In the Question wizzard I didn't spot the .NET.
I am using the pure C++ with WIN32.
How can I changes zones?
0
 
johnnash1180Commented:
In pure C++, I think that there is no fn to find the total elements in a enum data type.

You can try this... only if the elements values are sequential...

enum enumDigits {ZERO=0, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, DIGI_COUNT};

int totalDigits = enumDigits::DIGI_COUNT

The element DIGI_COUNT will always contain the count of the elements in the enum data type.

John Nash.
0
 
zordesAuthor Commented:
Thanks
I have expected something like this.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now