遇到点问题,怎么修改
#include"stdio.h"
enum COLORS {BLACK,BLUE,GREEN,CYAN,RED,MAGENTA,BROWN,LIGHTGRAY,LIGHTGRAY,LIGHTBLUE,LIGHTGREEN,LIGHTCYAN,LIGHTCYAN,LIGHTMAGENTA,YELLOW,WHITE};
void main()
{ enum COLORS a,b,c;
enum COLORS *pa;
int d=-2;
a=RED;
b=WHITE;
printf("\na=%d b=%d c=%d d=%d",a,b);
c=a+b;
if(a>b) pa=&a;
else pa=&b;
*pa=d;
printf("\na=%d b=%d c=%d d=%d",a,b,c,d);
}
--------------------Configuration: helloc - Win32 Debug--------------------
Compiling...
helloc.cpp
D:\VC语言\helloc\helloc.cpp(2) : error C2086: 'LIGHTGRAY' : redefinition
D:\VC语言\helloc\helloc.cpp(2) : error C2086: 'LIGHTCYAN' : redefinition
D:\VC语言\helloc\helloc.cpp(10) : error C2440: '=' : cannot convert from 'int' to 'enum COLORS'
Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast)
D:\VC语言\helloc\helloc.cpp(13) : error C2440: '=' : cannot convert from 'int' to 'enum COLORS'
Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast)
执行 cl.exe 时出错.
helloc.exe - 1 error(s), 0 warning(s)
[解决办法]
D:\VC语言\helloc\helloc.cpp(2) : error C2086: 'LIGHTGRAY' : redefinition
这个是说变量重定义了,你是不是之前定义过,或者是系统已定义
D:\VC语言\helloc\helloc.cpp(10) : error C2440: '=' : cannot convert from 'int' to 'enum COLORS'
Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast)
这个说你定义的变量不能转为int
[解决办法]
enum Days // Declare enum type Days{ saturday, // saturday = 0 by default sunday = 0, // sunday = 0 as well monday, // monday = 1 tuesday, // tuesday = 2 wednesday, // etc. thursday, friday} today; // Variable today has type Daysint tuesday; // Error, redefinition of tuesdayenum Days yesterday; // Legal in C and C++Days tomorrow; // Legal in C++ onlyyesterday = monday;int i = tuesday; // Legal; i = 2yesterday = 0; // Error; no conversionyesterday = (Days)0; // Legal, but results undefined