Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
組合には、現在使用されているメンバー(またはメンバーがいる場合)をテストするための制御構造がありますか?未定義の振る舞いがあなたのプログラムにあるのは決して良いことではないので、私はこれを求めています。
いいえ、そのようなメカニズムは既成のものではありません。あなたはそれを自分で世話する必要があります。通常のアプローチは、を:でラップするunionことstructです。
union
struct
struct MyUnion { int whichMember; union { //whatever } actualUnion; };
つまりMyUnion x;、x.whichMemberどのフィールドがx.actualUnion使用されているかがわかります(ただし、機能を実装する必要があります)。
MyUnion x;
x.whichMember
x.actualUnion