§9.5/9 from the C++11 Standard (emphasis mine):
A union-like class is a union or a class that has an anonymous union as a direct member. A union-like class
X
has a set of variant members. IfX
is aunion
, a non-static data member ofX
that is not an anonymous union is a variant member ofX
.
Is the part in bold saying that between a union-like class that is either a class or a union, only if it is a union can it have a non-static variant member that is not an anonymous union? If this is so, why? And what practical difference does it make in code?
I'm actually questioning whether this statement meant to say "If X
is a union-like class...". It would make full sense to me then.
Either way, this clause has been bugging me for the past few days and I wish to fully comprehend what it is stating.
No, your attempted clarification is wrong. Here is a union-like class X:
struct X
{
int a;
union {
double b;
long c;
};
};
X::a
is a non-static data member of a union-like class X
that is not an anonymous union. But it most definitely is NOT a variant member.
All non-static data members of a union are variant members. For union-like classes which are not unions, only those nested within union subobjects are variant members.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With