zoukankan      html  css  js  c++  java
  • iOS 开发-- enum与typeof enum用法

    一, 两者的用法

      枚举类型定义用关键字enum标识,形式为:

    enum标识符

    {

      枚举数据表

    };

    enum用来定义一系列宏定义常量区别用,相当于一系列的#define ** **,当然它后面的标识符也可当作一个类型标识符。

    typedef :typedef为C语言的关键字,作用是为一种数据类型定义一个新名字。这里的数据类型包括内部数据类型(int, char等)和自定义的数据类型(struct等)

    enum是枚举类型,有了typedef的理解容易看出,typedef enum定义了枚举类型,类型变量取值在enum{}范围内取,在使用中二者无差别。

    例如:

    enum HorizontalTitleAlignment

    {

        HorizontalTitleAlignmentLeft,

        HorizontalTitleAlignmentCenter,

        HorizontalTitleAlignmentRight

    };

    HorizontalTitleAlignmentCenter的值为2。

    typedef enum则是用来定义一个数据类型,那么该类型的变量值只能在恶奴们定义的范围内取。

    typedef enum {

        UIButtonTypeCustom = 0,           // no button type

        UIButtonTypeRoundedRect,          // rounded rect, flat white button, like in address card

        UIButtonTypeDetailDisclosure,

        UIButtonTypeInfoLight,

        UIButtonTypeInfoDark,

        UIButtonTypeContactAdd,

    } UIButtonType;

    那么UIButtonType表示一个类别,它的值只能是UIButtonTypeCustom...

  • 相关阅读:
    线程池的状态整理
    线程池 ThreadPoolExecutor 源码整理
    ReentrantReadWriteLock 源码分析
    ReentrantLock 锁释放源码分析
    编译Hadoop源码
    Ubuntu安装secureCRT
    ubuntu中为hive配置远程MYSQL database
    解决Ubuntu下sublime3无法输入中文
    Ubuntu下安装PAC Manager
    Git起步--git安装与初次运行git前配置
  • 原文地址:https://www.cnblogs.com/wmx-rj/p/4997102.html
Copyright © 2011-2022 走看看