P
Peter Olcott
Why can a union have a member with a copy constructor?
Why can a union have a member with a copy constructor?
Sam said:How do you know when that specific union member should be constructed?
What do you think should happen when two or more union members have
constructors?
You should be able to figure out the answer to your questions, by yourself.
That's because there isn't one. This isn't the same as a unionPeteOlcott said:If a class includes a union the class could also include a member that
indicates which element of the union is intended. In this case I see
no reason why this class that includes a union could not have a copy
constructor.
Carrying this same idea further this single member could be the first
element of a union of structs. In this case the union itself could
directly support a copy contructor, because this first element would
always indicate which of the structs is intended.
Because it's not a class.
In other words, Bjarne Stroustrup says so, as well as Dennis
Ritchie, and we, paltry followers, endorse it.
If a class includes a union the class could also include a
member that indicates which element of the union is intended.
In this case I see no reason why this class that includes a
union could not have a copy constructor.
Carrying this same idea further this single member could be
the first element of a union of structs. In this case the
union itself could directly support a copy contructor, because
this first element would always indicate which of the structs
is intended.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.