I may be mistaken, but the basic explanation I've found has been that the union can't initialize because it doesn't know which member's constructor to call. The compiler can not automatically generate a constructor for the union.
Why is the user not allowed to define the unions constructor? This would remove said issue and allow the presence of union members that have a non-trivial constructor/destructor.
Also, why can't a union member have any custom constructors? The previous explanation doesn't stand for custom constructors.
Update 1:
Example:
struct SQuaternion
{
union
{
S3DVector Axis;
struct
{
float X;
float Y;
float Z;
};
};
float W;
};
Note: The issue here seems to be that the union is anonymous. As such, how would one name the constructor of the union? It seems impossible to do so, merely because it has no name, and for no other reason. It'd be a terrible reason if it was a simple lexical issue...
Update 2: Simply by wrapping the offending member in an enclosing anonymous structure, the error disappears. I suppose this is the closest thing one can do with an anonymous union. The fact that it ceases to be an issue still seems strange...
structs
aren't officially allowed either. – Sponger