| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Wat" |
| Date: |
15 Dec 2004 12:59:19 AM |
| Object: |
question of enum |
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!
.
|
|
| User: "Siemel Naran" |
|
| Title: Re: question of enum |
15 Dec 2004 02:58:49 AM |
|
|
"Wat" <welwat@hotmail.com> wrote in message
news:bhRvd.126691$7i4.39519@bgtnsc05-
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) { ... } \
...
.
|
|
|
|
| User: "Mike Wahler" |
|
| Title: Re: question of enum |
15 Dec 2004 01:11:26 AM |
|
|
"Wat" <welwat@hotmail.com> wrote in message
news:bhRvd.126691$7i4.39519@bgtnsc05-news.ops.worldnet.att.net...
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
Thanks for your comments!
.
|
|
|
|

|
Related Articles |
|
|