//學習 聯合: 聯合不能包含帶有構造函數或析構函數的成員,因為無法保護其中對象以防止破壞,
//也不能保證在聯合離開作用域時能調用正確的析構函數。
/******************************************************************************************
#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;
}