3 ms·
C++ allows accessing inactive members in the special case when the active member shares a "common initial sequence" with the particular inactive member. So yea
by planede 4y ago
C++ allows accessing inactive members in the special case when the active member shares a "common initial sequence" with the particular inactive member.
So yeah, it's possible to store the tag in the common initial sequence of all the union members.
This is quite niche and rarely used. Most of the time it makes more sense to have the tag outside. Sometimes the tag in the common initial sequence allows the whole data structure to pack better than with a tag outside of the union.