Quick question regarding unions. I understand why a type I put in a union has to have a trivial default constructor. So my class definition is:
class MyClass {
public:
MyClass() {}
MyClass(...) { /* other constructor */ }
};
Now when I declare a union like so:
union MyUnion {
int numbers[4];
MyClass instance;
};
my compiler (the one in Visual Studio 2005 SP1) complains that MyClass has a non-trivial default constructor. However, this compiles without problem:
union MyUnion {
int numbers[4];
struct {
MyClass instance;
};
};
Can somebody enlighten me why this
does work?