问题
I would like to know the difference between structure and union for one member data type if there is any.
回答1:
In C: None. The famous "space-saving joke" #define struct union
is almost not a joke.
In C++98: Unions can only have POD members, non-union classes can have arbitrary members.
In C++11: Unions can have arbitrary data members of object type (but not of reference type), but their use is more restricted that that of non-union classes. (Namely: a union cannot have virtual member functions, cannot be a base class and cannot have base classes.) Also, you have to write more code to make a one-member union work as opposed to a one-member non-union class, since you have to write constructors and the destructor yourself.
来源:https://stackoverflow.com/questions/26572432/is-there-any-difference-between-structure-and-union-if-we-have-only-one-member