Hi i have an struct like this:
struct float2 {
float a;
float b;
};
now i can access members like this:
float2 f;
f.a = 1;
f.b = 2;
i want to access a and b with other alias as well:
float2 f;
f.a = 1;
f.b = 2;
f.x = 3;
f.y = 4;
f.w = 5;
f.h = 6;
f.width = 7;
f.height = 8;
x, w, width
must refer too same memory of a
and y, h, height
must refer to b
i tried 2 ways but one of them cost memory and one cost performance(i'm not sure):
struct float2
{
float a;
float b;
// plan a ->
float& x;
float& y;
float& w;
float& h;
float2(float _a, float _b) : a(_a), b(_b), x(a), y(b), w(a), h(b) {}
// plan b ->
float& width() {
return a;
}
float& height() {
return b;
}
};
is there any compile time way?
thanks.