I use Visual Studio, and I've noticed that there's no support for unrestricted unions. I've vritten a vec4 structure, basicly this:
template<class T>
struct vec4
{
T x, y, z, w;
vec4() :x(0), y(0), z(0), w(0) {}
vec4(T x, T y, T z, T w) :x(x), y(y), z(z), w(w) {}
vec4(const vec4& v) :x(v.x), y(v.y), z(v.z), w(v.w) {}
};
So the point is that I don't want to write vec2i (integer) vec2d (double) ect... separately. Then I made a 4 by 4 matrix:
template<class T>
struct mat4
{
T elements[16];
mat4()
{
for (int i = 0; i < 4 * 4; i++)
{
elements[i] = 0;
}
}
};
Again, the point is that I don't want to write all the separate types. I want to access the matrix columns as vec4s. But if I do this:
union
{
T elements[16];
vec4<T> columns[4];
};
I get C2621. As far as I know I can do this in GCC however I would like to avoid switching my development environment. Is there a workaround for this?
Edit: I've tried tricks like this:
vec4<T> * column(int col)
{
return ((vec4<T>*) (((vec4<T>*)elements) + (sizeof(vec4<T>) * col)));
}
However this seems to give me a bad result.