//學習 聯合: 聯合不能包含帶有構造函數或析構函數的成員,因為無法保護其中對象以防止破壞,
          //也不能保證在聯合離開作用域時能調用正確的析構函數。
          /******************************************************************************************
          #include "stdafx.h"
          #include <string>
          #include <fstream>
          #include <iostream>
          #include <algorithm>
          #include <map>
          #include <vector>

          using namespace std;

          int _tmain(int argc,_TCHAR* argv[])
          {
          ?//定義聯合類型
          ?union union_1? {
          ??char??? ccc;
          ??int???? kkk;
          ??float?? xxx;
          ?};

          ?//聲明聯合變量
          ?union union_1 uuu;

          ?// 使用聯合變量中的字符型成員
          ?uuu.ccc = '*';
          ?cout << uuu.ccc << endl;//運行結果:*

          ?// 使用聯合變量中的整型成員
          ?uuu.kkk = 1000;
          ?cout << uuu.kkk << endl;//運行結果:1000

          ?// 使用聯合變量中的浮點型成員
          ?uuu.xxx = 3.1416f;
          ?cout << uuu.xxx << endl;//運行結果:3.1416

          ?//聲明聯合變量時初始化
          ?union_1 uuu1 = {'A'};

          ?//同時引用聯合變量的各成員
          ?cout << uuu1.ccc << endl;//運行結果:A
          ?cout << uuu1.kkk << endl;//運行結果:65
          ?cout << uuu1.xxx << endl;//???運行結果:9.10844e-044
          ?return 0;
          }

          posted on 2008-04-08 23:47 -274°C 閱讀(599) 評論(0)  編輯  收藏 所屬分類: C++

          常用鏈接

          留言簿(21)

          隨筆分類(265)

          隨筆檔案(242)

          相冊

          JAVA網站

          關注的Blog

          搜索

          •  

          積分與排名

          • 積分 - 916114
          • 排名 - 40

          最新評論

          主站蜘蛛池模板: 扎鲁特旗| 公安县| 彩票| 滁州市| 房产| 辽宁省| 高尔夫| 漠河县| 浦县| 泸州市| 元阳县| 壤塘县| 施甸县| 湟源县| 个旧市| 南宁市| 桂东县| 丰顺县| 台前县| 连州市| 文成县| 大宁县| 阿图什市| 固安县| 冕宁县| 绥中县| 越西县| 蚌埠市| 岑巩县| 兴化市| 和林格尔县| 建阳市| 新和县| 天长市| 桐柏县| 遂溪县| 富蕴县| 女性| 灵武市| 三都| 南宫市|