question of enum

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wat

    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!


  • Mike Wahler

    #2
    Re: question of enum


    "Wat" <welwat@hotmail .com> wrote in message
    news:bhRvd.1266 91$7i4.39519@bg tnsc05-news.ops.worldn et.att.net...[color=blue]
    > When read a sample code using "enum", it uses min and max values for[/color]
    "enum"[color=blue]
    > type.
    >
    > enum MyType
    > {
    > MyType_Min,
    > ...
    > MyType_Max
    > };
    >
    > Are MyType_Min and MyType_Max used for checking the value range of[/color]
    "MyType"[color=blue]
    > when using "MyType" type?[/color]

    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
    [color=blue]
    >
    > Thanks for your comments!
    >
    >[/color]


    Comment

    • Siemel Naran

      #3
      Re: question of enum

      "Wat" <welwat@hotmail .com> wrote in message
      news:bhRvd.1266 91$7i4.39519@bg tnsc05-
      [color=blue]
      > When read a sample code using "enum", it uses min and max values for[/color]
      "enum"[color=blue]
      > type.
      >
      > enum MyType
      > {
      > MyType_Min,
      > ...
      > MyType_Max
      > };[/color]

      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) { ... } \
      ...


      Comment

      Working...