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...

  • 相关阅读:
    求解一元二次方程
    常用电脑软件
    c语言的布尔量
    unsigned int数据类型最大数
    int数据类型的最大数
    习题6-8 统计一行文本的单词个数
    习题6-6 使用函数输出一个整数的逆序数
    习题6-5 使用函数验证哥德巴赫猜想
    习题6-4 使用函数输出指定范围内的Fibonacci数
    C#委托、泛型委托
  • 原文地址:https://www.cnblogs.com/wmx-rj/p/4997102.html
Copyright © 2011-2022 走看看