c++11 - C++ - Is there a way to create alias for field -
is there way create alias class/stuct filed in c++11 ? mean i've got class class vector4 { public: float x,y,z,w; } i got alias typedef vector4 color; is there way create aliases vector4 x,y,z,w fields work color r,g,b,a ? just define vector4 this, using anonymous unions (without anonymous structs, though common extension). typedef struct vector4 { union{float x; float r;}; union{float y; float g;}; union{float z; float b;}; union{float w; float a;}; } vector4; typedef vector4 color; if cannot redefine vector4, might instead define layout-compatible standard-layout class , use dreaded reinterpret_cast . works because standard layout classes having layout-compatible members compatible. struct color { float r, g, b, a; } standard quote: a standard-layout class class that: — has no non-static data members of type non-standard-layout class (or array of such types) or reference, — has no virtual functions (10.3) ...