c++ Syntax of a constructor's initialization list with a data member struct?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/1480430/member-initialization-of-a-data-structures-members">Member initialization of a data structure&rsquo;s members</a>  </p>
</blockquote>

<p>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 ;)). 
<a href="http://stackoverflow.com/questions/1480430/member-initialization-of-a-data-structures-members">http://stackoverflow.com/questions/1480430/member-initialization-of-a-data-structures-members</a></p>

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

<p>Hi,</p>

<p>I have a class that looks like this:</p>

<pre><code>class Button
{
    private:
        SDL_Rect box;
    public:
        Button(int x, int y, int w, int h);
}
</code></pre>

<p>Where box is one of <a href="http://www.libsdl.org/cgi/docwiki.cgi/SDL_Rect" rel="nofollow">these</a> 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,</p>

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

<p>I would like to appease it. I can't figure out the stupid syntax though. I've tried</p>

<pre><code>Button::Button(int x, int y, int w, int h ) :
    box(0,0,0,0)
</code></pre>

<p>but that just results in</p>

<pre><code>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&amp;)|
c:\programming\mingw-4.4.0\bin\..\lib\gcc\mingw32\4.4.0\..\..\..\..\include\SDL\SDL_video.h|50|note:                 SDL_Rect::SDL_Rect()|
</code></pre>

<p>I tried <code>box = blah</code> or <code>box.x = blah</code> or <code>box.x(blah)</code>, but they failed.</p>

<p>I also tried <code>box({0,0,0,0})</code>, and <code>box{0,0,0,0}</code>,</p>

<pre><code>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|
</code></pre>

<p>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. </p>

<p>In the end I managed to get away with:</p>

<pre><code>Button::Button(int x, int y, int w, int h ) :
    box()
{
    box.x = x;
    box.y = y;
    box.w = w;
    box.h = h;
}
</code></pre>

<p>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?</p>
