So I have a vec4 class that uses members x,y,z,w which you can access using
point.x point.y etc.
However I want to reuse this vec4 class to be my color class (it already supports scalar multiplication, operator overloading lots of other nice stuff)
I just want to be able to refer to the members using another notation:
color.r
color.g
color.b
etc.
Is there anyway I can do this using a macro or other syntactic sugar?
If you are using Visual Studio (and are sure that it is the only target IDE…) you can use the following:
It will yield warnings
warning C4201: nonstandard extension used : nameless struct/union, though you can disable it.EDIT: as it turns out gcc supports this extension as well.