努力工作,关爱家人

博客园 首页 新随笔 联系 订阅 管理
enum 和 typedef, 在两个小节中书中分别出现了2个例子,如下

enum direction {north, south, east, west};

typedef enum {north, south, east, west} direction;

不禁产生疑问,这两个有什么区别,仔细对照了一下,发现是这样的:

大同小异,

同: 都是申明了一个枚举类型。

异:在使用该枚举类型定义变量的时候,语法不一样,举例如下:

1 enum direction {north, south, east, west};   
3 enum direction facing = north; 
4
5 typedef enum {north, south, east, west} direction;    
7 direction facing = north;
posted on 2011-12-09 10:53  jelink  阅读(2611)  评论(0)    收藏  举报