I'm trying to make a generic vector class. While I can do something like this:
struct vector3 {
union {
struct {
float x;
float y;
float z;
};
float v[3];
};
};
I cannot do this:
template<int N, typename S, typename T = double>
class vec {
union {
T data[N];
S;
};
};
struct XY { REAL x, y; };
typedef vec<2, XY, REAL> Vector2;
because "S does not declare anything."
Is there any way to insert a generic template parameter as a member of a union? Essentially, I want to "inject" x and y fields into the vec class. Is there a better way of doing this?