question of enum



 DEVELOP > c-Plus-Plus > question of enum

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
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!


.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER