Do unions have a control structure to test which member is currently in use (or if it has any at all)? I’m asking this because undefined behavior is never a good thing to have in your program.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, no such mechanism exists off-the-shelf. You’ll have to take care of that yourself.
The usual approach is wrapping the
unionin astruct:So you have
MyUnion x;andx.whichMembertells you which field ofx.actualUnionis in use (you have to implement the functionality though).