Is there anything wrong with a union having one or more methods? Or anything to watch out for? (I can see constructors/destructors being problematic for schizophrenic reasons)
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.
From the C++03 & C++0x (Draft N3092) standards:
Initializing the union using the aggregate initializer syntax (
U u = { 42 };) or setting a member afterwards (U u; u.i = 42;) is not “problematic”. And neither is initializing it using a constructor (U u( 42 );).The only “catch” is that you cannot use the aggregate initializer syntax for a union that has a user defined constructor.