objective-c enum 与 typedef(转)

今天看到enum 和 typedef, 在两个小节中书中分别出现了2个例子,如下

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

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

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

大同小异,

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

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

 

 

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

 enum direction facing = north;  

 

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

 direction facing = north;

 

原地址:

http://xiaoxuejie.iteye.com/blog/1574606

猜你喜欢

转载自lizi07.iteye.com/blog/1620377