枚举enum与typedef enum的区别

C里面定义enum变量的时候必须加enum
C/C++ code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
enum  TextType
{
     TM_ENGLISH_ABC,
     TM_ENGLISH_abc,
     TM_NUMBER,
     TM_SYMBOL,
     TM_PINYIN
};
int  main()
{
     enum  TextType x; //ok
     TextType y; //error
}


C/C++ code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
typedef  enum  TextType
{
     TM_ENGLISH_ABC,
     TM_ENGLISH_abc,
     TM_NUMBER,
     TM_SYMBOL,
     TM_PINYIN
}TextType;
 
int  main()
{
     enum  TextType x; //ok
     TextType y; //ok

你可能感兴趣的:(枚举enum与typedef enum的区别)