enum Question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amitbern
    New Member
    • Oct 2006
    • 6

    enum Question

    Hi, a little Q:
    typedef enum
    {
    NUM0 = 0,
    NUM1 = 1,
    NUM2 = 2,
    NUM3 = 3,
    } NUMBER;

    NUMBER test=NUM0;

    when i'm writing:
    test++
    i get an error, how can i do the ++ without the need to do casting like:
    test=(NUMBER)(t est+1);
    thanks
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    Originally posted by amitbern
    Hi, a little Q:
    typedef enum
    {
    NUM0 = 0,
    NUM1 = 1,
    NUM2 = 2,
    NUM3 = 3,
    } NUMBER;

    NUMBER test=NUM0;

    when i'm writing:
    test++
    i get an error, how can i do the ++ without the need to do casting like:
    test=(NUMBER)(t est+1);
    thanks
    in C++ you could overload the operator++() function

    Comment

    • Ganon11
      Recognized Expert Specialist
      • Oct 2006
      • 3651

      #3
      I'm not sure there's a way to overload operators on enumeratued types...

      As far as I know, there is no way to get an enum type from an enum type after incrementing - you have to explicitly cast it.

      As an aside, I'm not sure you have to put the = 0, = 1, etc. in the enum values...they are defaulted to the values 0, 1, 2,..., n-1, where n is the number of values.

      Comment

      Working...