C/C++UNION中包含STRUCT
测试环境: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、