联合

  1. 介绍联合类型的定义。

    // Example is from POSIX
    union sigval {
        int     sival_int;
        void   *sival_ptr;
    };
    
  2. 引入*详细的类型说明符,*它指定以下名称是联合类型的名称。如果已经声明了联合名称,即使被其他名称隐藏也可以找到它。如果联合名称尚未声明,则为前向声明。

    union foo; // elaborated type specifier -> forward declaration
    class bar {
      public:
        bar(foo& f);
    };
    void baz();
    union baz; // another elaborated type specifer; another forward declaration
               // note: the class has the same name as the function void baz()
    union foo {
        long l;
        union baz* b; // elaborated type specifier refers to the class,
                      // not the function of the same name
    };