Re: union float[3] and x,y,z
Gernot Frisch wrote:
Uhm...
Is there any way of making
float pos[3];
a union of
float x,y,z;
somehow, so I can use:
mything[0] = mything.y;
instead of mything.x = mything.y
Thanks in advice,
Hasn't this been discussed here a couple of times over the past
two-three months? No, there is no sense in making a union. The
only way you can manage that is if you stuff 'x', 'y', and 'x' in
some kind of struct inside that union. In structs members can
have padding, and in arrays they don't. So, it is conceivable
that your union trick is not going to work. A solution might be
struct Blah {
float pos[3];
float &x, &y, &z;
Blah() : x(pos[0]), y(pos[1]), z(pos[2]) {}
};
which makes it non-POD (members that are references). Or agree
to define 'x' as a function:
struct Blah {
float pos[3];
float& x() { return pos[0]; }
float x() const { return pos[0]; }
};
In any case, search the archives for "union padding array" and
some other keywords you can come up with.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask