您的位置:首页 > 编程语言 > C语言/C++

C/C++UNION中包含STRUCT

2017-02-23 09:43 381 查看
测试环境:Win7x64,cn_visual_studio_2010_ultimate_x86_dvd_532347.iso,qt-opensource-windows-x86-msvc2010_opengl-5.3.2.exe

1、

  1.1、测试代码:

struct struct01
{
union
{
int i;
int j;
};
};

struct struct02
{
union
{
struct
{
int i;
int j;
} ss01;
struct
{
int i;
int j;
} ss02;
} u01;
};

void MainWindow::on_pushButton_clicked()
{
struct01 s01 = {0};
s01.i = 100;
qDebug() << s01.i;
qDebug() << s01.j;

struct02 s02 = {0};
s02.u01.ss01.i = 99;
qDebug() << s02.u01.ss01.i;
qDebug() << s02.u01.ss02.i;
}


  1.2、控制台输出:

100
100
99
99


2、

3、
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: