代码如下:
#include <stdio.h>
struct Date
{
int mo, da, yr;
};
// Declare the Holder union.
union Holder
{
struct Date hdt;
int hint;
};
// The main() function.
int main()
{
union Holder hld = {{6, 24, 1940}};
printf("%d %d %d\n", hld.hdt.yr, hld.hdt.mo, hld.hdt.da);
printf("%d\n", hld.hint);
return 0;
}
匿名联合与匿名结构体:http://moosewoler.blog.163.com/blog/static/698660520105264486311/
C++的使用参看:http://blog.csdn.net/kunshan_shenbin/article/details/5747063