0

i have an c2675 error when using c++.

#include<stdio.h>
int main(void){
   enum months {jan=1, feb, mar, apr, jun, aug, sep, oct, nov, dec};
   enum TV { kbs1 =9, kbs2 = 7, mbc =11, sbs = 6};
   enum months mon;

   printf("kbs1 : %d",kbs1);
   printf("kbs2 : %d",kbs2);
   printf("mbc : %d", mbc);
   printf("sbs : %d", sbs);

   for(mon = jan; mon<=dec; ++mon){
       printf("%d",mon);}
   return 0;

But, there is a result...

error C2675: unary '++' : 'main::months' does not define this operator or a conversion to a type acceptable to the predefined operator.

Please help me how to solve this problem... T_T

1 Answers1

0

One (ugly) solution is :

for( mon = jan; mon <= dec; mon = (months)(mon + 1) )
{
    printf("%d", mon);
}

But it only works because the values of your enum are continuous and won't work with your TV enum for exemple.

Chris R.
  • 562
  • 7
  • 31