我如何声明一个在联合中的结构的变量,而这个联合在另一个结构中

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;

    }; 

  };


 };

我想声明一个变量为struct B的变量,我该怎么做?

标准不允许匿名中的嵌套类型 union。您的代码不合法​​。

来自 C++ 标准草案 N3337:

9.5 Unions

...

5 A union of the form

union { member-specification } ;

is called an anonymous union; it defines an unnamed object of unnamed type. The member-specification of an anonymous union shall only define non-static data members. [ Note: Nested types and functions cannot be declared within an anonymous union. — end note ]