我如何声明一个结构的变量,该变量位于联合中,而该联合位于另一个结构中
How can i declare a variable of a struct which is in a union and this union is in another struct
示例代码
struct A
{
union
{
struct B
{
short a:1;
short b:1;
};
};
};
我想将一个变量声明为结构 B 的变量。我该怎么做?
该标准不允许在匿名union
中使用嵌套类型。你的代码是不合法的。
从C++标准草案N3337:
9.5 工会
。
5 形式的并集
union
{ 成员规范 } ;称为匿名联合;它定义未命名类型的未命名对象。匿名联合的成员规范应仅定义非静态数据成员。[ 注意:嵌套类型和函数不能 在匿名工会内宣布。— 尾注 ]
相关文章:
- 在类构造函数中使用结构变量
- 在类构造函数中定义结构变量的参数
- 为什么我们再次从结构对象创建结构变量?
- 如何从其他结构访问受保护的结构变量
- 指向结构变量的指针未保存到eeprom
- 为什么我的程序没有更改结构变量中的值?
- 在 CPP 中初始化 typedef 结构变量
- 带有大结构变量的 CUDA 内核函数给出了错误的结果
- 有没有办法初始化不涉及编写构造函数的新结构变量?
- 结构变量查询
- 在结构声明的分号之前声明的结构变量是否为全局变量
- C++ 如何访问指针的结构变量
- 使用指向结构变量成员的指针访问该结构的成员的地址
- 为什么在 sizeof() 函数中与 * 运算符一起使用和不使用 * 运算符时,指向结构变量的指针大小会有所不同?
- 如何在类别内的类中访问类中的结构变量
- 尝试使用文本文件初始化多个结构变量
- 从类对象到结构变量的 memcpy
- C++结构变量初始化时出现问题
- 如何在 C++ 中使用带有类/结构变量的列表
- 动态数组添加元素而不创建结构变量/对象