Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6906585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:19:44+00:00 2026-05-27T08:19:44+00:00

So I have a vec4 class that uses members x,y,z,w which you can access

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:19:44+00:00Added an answer on May 27, 2026 at 8:19 am

    If you are using Visual Studio (and are sure that it is the only target IDE…) you can use the following:

    #include <cassert>
    
    union vec4
    {
        struct 
        {
            float x;
            float y;
            float z;
            float w;
        };
        struct
        {
            float r;
            float g;
            float b;
            float a;
        };
    };
    
    int main()
    {
        vec4 vec = { 0 };
        vec.y = 10.0f;
        assert(vec.g == 10.0f);
        return 0;
    }
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a running program that uses glVertexPointer, glNormalPointer etc to draw a large
I have a small class that allows me to load shaders and use them
I have a very basic fragment shader which I want to output 'gl_PrimitiveID' to
I have a VBO with points in it, that I can render fine with
I have a strange problem that I can't figure out when trying to do
I have the following vertex shader: attribute vec4 Position; attribute vec4 SourceColor; varying vec4
Have a singleton class for BNRItemStore, but when I tried to call it, I
Have just started using Google Chrome , and noticed in parts of our site,
I have a scene that is rendered to texture via FBO and I am
I have this very simple (yet big) code that doesn't work. The triangle doesn't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.