question of enum

W

Wat

When read a sample code using "enum", it uses min and max values for "enum"
type.

enum MyType
{
MyType_Min,
...
MyType_Max
};

Are MyType_Min and MyType_Max used for checking the value range of "MyType"
when using "MyType" type?

Thanks for your comments!
 
M

Mike Wahler

Wat said:
When read a sample code using "enum", it uses min and max values for "enum"
type.

enum MyType
{
MyType_Min,
...
MyType_Max
};

Are MyType_Min and MyType_Max used for checking the value range of "MyType"
when using "MyType" type?

We cannot tell without seeing the code that uses them. But they could be.

I have seen an extra 'dummy' enumeration value placed last in
a default sequential enumeration for the purpose of denoting the number
of values in an enum.

enum e
{
a,
b,
z
};

cout << "number of enum values: " << z << '\n';

If we insert other names anywhere before 'z', 'z' still gives
the correct result. (this of course falls apart if any of the
values are given other than default values).

-Mike
 
S

Siemel Naran

When read a sample code using "enum", it uses min and max values for "enum"
type.

enum MyType
{
MyType_Min,
...
MyType_Max
};

I often start my enums at 0, so there is no Type_Min, but there is a
Type_Max. I then use this in max value as the size of an array. For
example,

enum Status { Open, Closed, Status_Max };
string Status_text[Status_Max] = { "Open", "Closed" };

In another usage, I have macros

#define define_enum_one_operators(Enum,T,min,max) \
friend inline Enum& operator++(Enum& e) { ... } \
...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,184
Messages
2,570,979
Members
47,580
Latest member
kim2namjoon

Latest Threads

Top