posts - 131,  comments - 234,  trackbacks - 0

//学习 联合: 联合不能包含带有构造函数或析构函数的成员,因为无法保护其中对象以防止破坏,
//也不能保证在联合离开作用域时能调用正确的析构函数。
/******************************************************************************************
#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 阅读(64) 评论(0)  编辑  收藏 所属分类: C++

标题  
姓名  
主页
验证码 *  
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
 

<2008年4月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

黄树林里分叉两条路,而我,我选择了较少人迹的一条,使得一切多麽地不同。


常用链接

留言簿(11)

随笔分类(136)

随笔档案(131)

JAVA网站

关注的Blog

最新随笔

搜索

  •  

积分与排名

  • 积分 - 73843
  • 排名 - 104

最新评论

阅读排行榜

评论排行榜