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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:19:20+00:00 2026-05-16T20:19:20+00:00

I am trying to initialize a 2D array of structs in C++, but am

  • 0

I am trying to initialize a 2D array of structs in C++, but am getting an error. Can someone please tell me what am I doing wrong? I have rechecked the braces and they seem to be fine.

My code:


struct CornerRotationInfo {
  bool does_breed;
  int breed_slope;
  bool self_inversion;
  int self_slope;
  inline CornerRotationInfo(bool db, int bs, bool si, int ss) : does_breed(db), breed_slope(bs), self_inversion(si), self_slope(ss) {};
};

#define NO false
#define YES true
#define R 1
#define F -1
#define H 0
static const CornerRotationInfo corner_rot_info[3][8] = {
  // { 0, 45, 90, 135
  //  180, 225, 270, 315 }
  {
    { NO, F, NO, F }, {YES, F, NO, H }, {YES, H, NO, R}, {NO, R, YES, R },
    { NO, F, NO, F }, {YES, F, NO, H }, {YES, H, NO, R}, {NO, R, YES, R }
  }, // Falling
  {
    { NO, H, NO, H }, {YES, F, NO, R }, {NO, H, YES, H }, {YES, R, NO, F },
    { NO, H, NO, H }, {YES, F, NO, R }, {NO, H, YES, H }, {YES, R, NO, F }
  }, // Horizontal
  {
    { NO, R, NO, R }, {NO, F, YES, F }, {YES, H, NO, F}, {YES, R, NO, H },
    { NO, R, NO, R }, {NO, F, YES, F }, {YES, H, NO, F}, {YES, R, NO, H }
  }  // Rising
};

#undef NO
#undef YES
#undef R
#undef F
#undef H

The error I am getting is:

Transformation.C:72: error: brace-enclosed initializer used to initialize `const
 CornerRotationInfo'
  • 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-16T20:19:20+00:00Added an answer on May 16, 2026 at 8:19 pm

    When you are trying to use aggregate initializer to initialize an array of objects with used-declared constructor, the syntax you can use depends significantly on how many parameters the individual element’s constructor has.

    If the constructor has (read: accepts) only one parameter, you can use “normal” aggregate initializer syntax, as in

    std::string a[2] = { "abc", "def" };
    

    However, if the constructor you want (or have) to use requires more than one parameter, you cannot pass the constructor arguments as a {}-enclosed list. You have no other choice but to explicitly create temporary objects of the target type in the aggregate initializer, as in

    std::vector v[2] = { std::vector(10, 3), std::vector(8, 2) };
    

    This is exactly what you have to do in your case

    static const CornerRotationInfo corner_rot_info[3][8] = {
      {
        CornerRotationInfo(NO, F, NO, F), 
        CornerRotationInfo(YES, F, NO, H),
        ...
      },
      ...
    };
    

    and so on.

    Note that in C++ initialization performed by an {}-enclosed initializer list is conceptually a copy-initialization, which means that you are not really changing much by creating those temporaries explicitly. I.e. conceptually the temporaries are always created during aggregate initialization. The compiler will normally optimize them away anyway.

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

Sidebar

Related Questions

I am trying to initialize the following array of the following struct, but my
I am trying to initialize an array of bools like so: bool FcpNumberIsOk[MAX_FCPS]={true}; but
I have a list string tag. I am trying to initialize a dictionary with
I'm trying to write a simple program in VC++ which will just initialize the
Trying to make a make generic select control that I can dynamically add elements
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation
Trying to do this sort of thing... WHERE username LIKE '%$str%' ...but using bound
Forgive me if I'm just blatantly missing something, but I'm trying to make the
Edited again because it originally wasn't clear that I'm trying to initialize the arrays
I'm trying to create a structure array which links input strings to classes as

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.