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 7057411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:58:58+00:00 2026-05-28T03:58:58+00:00

I am building a class that has a union for its matrix data, however,

  • 0

I am building a class that has a union for its matrix data, however, I can only get it compile when I do not have a name for the struct\union. However, with a higher level warning level (four on visual studio) I will a warning saying

warning C4201: nonstandard extension used : nameless struct/union

I looked into it, and I don’t seem to be able to find a way to prevent this. Anyway possible that I know of will cause a different compiler error related to the declaration of one or the other. How can I prevent getting this warning and make it conform to standards, without just disabling the warning.

    union
    {
        struct
        {
            F32 _11, _12, _13, _14;
            F32 _21, _22, _23, _24;
            F32 _31, _32, _33, _34;
            F32 _41, _42, _43, _44;
        };
        F32 _m[16];
    };

(Yes, I know there is matric libraries available. Please do not turn this into a “use xxx library” discussion, I am doing this to expand my knowledge of C++”.)

  • 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-28T03:58:59+00:00Added an answer on May 28, 2026 at 3:58 am

    Naming it seems best. Anonymous unions are allowed in C++, just not structs.

    union
    {
        struct foo
        {
            F32 _11, _12, _13, _14;
            F32 _21, _22, _23, _24;
            F32 _31, _32, _33, _34;
            F32 _41, _42, _43, _44;
        } bar;
        F32 _m[16];
    };
    

    You can use references/macros to allow access without bar.

    F32& _11 = bar._11;
    F32& _12 = bar._12;
    

    Essentially the same as an anonymous struct. I don’t really recommend this though. Use bar._11 if possible.


    Private/public (sorta):

    struct mat 
    {
      struct foo 
      {
        friend class mat;
        private:
          F32 _11, _12, _13, _14;
          F32 _21, _22, _23, _24;
          F32 _31, _32, _33, _34;
          F32 _41, _42, _43, _44;
      };
      union
      {
        foo bar;
        F32 _m[16];
      };
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a tool. I have a Collection Class that stores data gathered
I'm building a class library that will have some public & private methods. I
I'm building a class that interacts with an API. Say the API has a
I have a web app I'm building that has about 50 forms. I have
I am building an iPhone app that has some default data inside it via
I'm building a relatively simple class (ex: Person) for an ASP.NET application that has
I am building a FLA file that has a document class Main and in
I am building a class that has a mapping of strings to integers. So
I'm building a Zend form that has a dropdown/select menu populated with data from
I'm building a class that automatically loads a DB record, looks at each DB

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.