I have two types defined in a header file like so:
struct vec2{
float x;
float y;
vec2() : x(0), y(0) {}
};
struct vec3{
float x;
float y;
float z;
vec3() : x(0), y(0), z(0) {}
};
In some C++ file I would like to be able to write:
vec2 a2 = {2,4};
vec3 a3 = vec2(a2);
//This would give me a3 with a z-value of 0.
Which would work by adding this to the header:
vec3(vec2 a) : x(a.x), y(a.y), z(0) {}
But I would also like to be able to write:
vec3 a3 = {1,2,4};
vec2 a2 = vec3(a3); //Where this would result in a3's z component being dropped.
Is this possible? Would I need to typedef it somehow so the compiler knows ahead of time what size the 2 structures are?