How to increase the number of enumerations in VS C ++ 6.0?

I copy and paste code that increases the number of listings:

myenum++;  

This code worked fine since it was compiled in VS.NET C ++ 2003

I am currently developing in VS 6.0 and getting an error:

error C2676: binary '++': 'enumeration ID' does not define this operator or type conversion acceptable for a predefined operator

How can I make it behave the same in 6.0?

+5
source share
4 answers

Try converting to int, add one (+1) and convert back to enumeration.

+2
source

++ . ? (, ), , , . * , Complex, , , ++!

, ++ , .

enum DayOfWeek {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};
inline DayOfWeek operator++(DayOfWeek &eDOW, int)
{
   const DayOfWeek ePrev = eDOW;
   const int i = static_cast<int>(eDOW);
   eDOW = static_cast<DayOfWeek>((i + 1) % 7);
   return ePrev;
}
+13

, , .

enum {
  A, 
  B,
  C,
}

May

enum {
  A = 0, 
  B = A + 1,
  C = B + 1,
}

int a = A;
a++;

,

enum {
  A = 2, 
  B = 4,
  C = 8,
}

+1 .

, ,

enum {
  FIRST,
  A = FIRST, 
  B,
  C,
  LAST = C
}

A C ?

What is the purpose of repeating an enumeration? Do you want to do "for all" or for some subset, is there really an enumeration order?

I would drop them all in a container and repeat, instead

  • unordered - use a set
  • ordered - vector or list
+4
source
myenum=(myenum_type)((int)myenum+1);

This is ugly, but it works.

+1
source

All Articles