枚举型自加运算问题求解
哪位大哥帮忙找一下下面程序的错误:我调试时提示:
错误 2 error C2676: binary '++' : 'wmain::color' does not define this operator or a conversion to a type acceptable to the predefined operator c:\documents and settings\颩,無心\my documents\visual studio 2005\projects\enum\enum\enum.cpp 15
这是个枚举型的例子,书上说枚举型可以自加运算,但这儿却出错;我用的VS2005调试的;好像VC6.0也是同样的错误;
#include "stdafx.h"
#define n "%-10s"
void main()
{
enum color{red,yellow,blue,white,black};
enum color i,j,l,pri;
int m,loop;
m=0;
for(i=red;i<=black;i++)
for(j=red;j<=black;j++)
if(i!=j)
for(l=red;l<=black;l++)
if((l!=i)&&(l!=j))
{
m=m+1;
printf("%-4d",m);
for(loop=1;loop<=3;loop++)
{
switch(loop)
{case 1:pri=i;break;
case 2:pri=j;break;
case 3:pri=l;break;}
switch(pri)
{
case red:printf(n,"red");break;
case yellow:printf(n,"yellow");break;
case blue:printf(n,"blue");break;
case white:printf(n,"white");break;
case black:printf(n,"white");break;
}
}
printf("\n");
}
}