How can I make this second struct work, when the first struct has a constructor?
I get error:
error C2620: member 'test::teststruct::pos' of union 'test::teststruct::<unnamed-tag>' has user-defined constructor or non-trivial default constructor
The code:
struct xyz {
Uint8 x, y, z, w;
xyz(Uint8 x, Uint8 y, Uint8 z) : x(x), y(y), z(z) {}
};
struct teststruct {
union {
Uint32 value;
xyz pos; // error at this line.
};
};
I could use a function to initialize the xyz struct, but wouldn’t it be a lot slower? Not to mention: I have tons of structs I need to create own function with a prefix like init_xyz() or etc, which isn’t nice. Is there any other way going around this problem?
Probably to avoid this:
What should happen, A and B constructors will both try to initialize the same memory in different ways. Instead of having some rule saying which will win, it was probably easier to say user defined constructors aren’t allowed.