Just to show an example that I find useful, imagine that you have a structure (vector) that represents coordinates in 3 three dimensions (x, y, z). But you also need a structure that represents colors, and also has three variables (red, green, blue). The structure of the colors and the vector are very similar, what changes is just the name of the member variables. In addition, Voce already has a wide range of vector manipulation functions, and it would be very useful if Voce also had them for the color structure. To solve your problem you could do the following:
struct vec3{
union{
struct{
float x, y, z;
};
struct{
float r, g, b;
};
};
};
using color = vec3;
And if you have for example a function that normalizes a vector you can also use to normalize the colors, without having to redefine the function.
But of course you could also define the structure vec3
only with the variables x, y and z, and use for the two tasks. But I think that this way the code becomes more natural.