Original Post
Is it legal c++ to use nameless structs and unions? I'm rewriting some old code and came up with this idea in a Vector3 class. It compiles and works but I'm not sure I should use it. Is there an other way to do it?
class Vector3
{
public:
union {
float v[3]; //x, y, z
struct { float x, y, z; };
};
//...
};
Vector3 vec;
// Then this is equal
vec.v[2] = 10.0f;
vec.z = 10.0f;