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

  • Home
  • SEARCH
  • 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 538731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:03:44+00:00 2026-05-13T10:03:44+00:00

Possible Duplicate: Member initialization of a data structure’s members EDIT: I typed the title

  • 0

Possible Duplicate:
Member initialization of a data structure’s members

EDIT:
I typed the title in last, and it gave me a lsit of related problems, as it usually does. At the bottom of this list was the exact same problem. (Using the exact same code ;)).
Member initialization of a data structure's members

AraK answers it fully, really. It appears I need to vote in order to close my own question?

Hi,

I have a class that looks like this:

class Button
{
    private:
        SDL_Rect box;
    public:
        Button(int x, int y, int w, int h);
}

Where box is one of these guys from SDL. Running with GCC with -Weffc++, just becasue I wanted to know what the warnings would be like, complains about the initialiser list,

file.cpp||In constructor 'Button::Button(int, int, int, int)':|
file.cpp|168|error: 'Button::box' should be initialized in the member initialization list|

I would like to appease it. I can’t figure out the stupid syntax though. I’ve tried

Button::Button(int x, int y, int w, int h ) :
    box(0,0,0,0)

but that just results in

file.cpp||In constructor 'Button::Button(int, int, int, int)':|
file.cpp|171|error: expected identifier before '{' token|
file.cpp|171|error: member initializer expression list treated as compound expression|
file.cpp|171|error: left-hand operand of comma has no effect|
file.cpp|171|error: right-hand operand of comma has no effect|
file.cpp|171|error: right-hand operand of comma has no effect|
file.cpp|171|error: no matching function for call to 'SDL_Rect::SDL_Rect(int)'|
c:\programming\mingw-4.4.0\bin\..\lib\gcc\mingw32\4.4.0\..\..\..\..\include\SDL\SDL_video.h|50|note: candidates are: SDL_Rect::SDL_Rect(const SDL_Rect&)|
c:\programming\mingw-4.4.0\bin\..\lib\gcc\mingw32\4.4.0\..\..\..\..\include\SDL\SDL_video.h|50|note:                 SDL_Rect::SDL_Rect()|

I tried box = blah or box.x = blah or box.x(blah), but they failed.

I also tried box({0,0,0,0}), and box{0,0,0,0},

file.cpp|169|error: extended initializer lists only available with -std=c++0x or -std=gnu++0x|
file.cpp|171|error: expected identifier before '{' token|

I don’t really want to be compiling against c++0x, really. Especially as I want this to be cross platform, and I don’t think many things support c++0x.

In the end I managed to get away with:

Button::Button(int x, int y, int w, int h ) :
    box()
{
    box.x = x;
    box.y = y;
    box.w = w;
    box.h = h;
}

Which seems entirely pointless to me. Is this the ‘correct’ way to do this? Isn’t this just the same as without the initialiser list?

  • 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-13T10:03:44+00:00Added an answer on May 13, 2026 at 10:03 am

    I see you found your solution, but please note that you could also get away with writing a class wrapper for SDL_rect, or even a global function SDL_rect createRect( int x, int y, int w, int h )

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

Sidebar

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.