![]() |
What does this syntax mean?
Hi, the following piece of code is rather obscure for me
struct Foo { Foo( int _x ) : x(_x) {} .... }; what's the meaning of that construct? I understand Foo() must be a constructor, right? But then what's with the syntax after the ":" ?? Thanks! Giuseppe |
Re: What does this syntax mean?
Giuseppe:G: wrote:
> Hi, the following piece of code is rather obscure for me > > struct Foo > { > Foo( int _x ) : x(_x) {} > .... > }; > > what's the meaning of that construct? I understand Foo() must be a > constructor, right? But then what's with the syntax after the ":" ?? > Look up initialiser lists. -- Ian Collins. |
Re: What does this syntax mean?
On Sun, 22 Jun 2008 21:02:45 +0200, G: <giuseppegalloneNO@spamgmail.com>
wrote: > Hi, the following piece of code is rather obscure for me > > struct Foo > { > Foo( int _x ) : x(_x) {} > ... > }; > > what's the meaning of that construct? I understand Foo() must be a > constructor, right? But then what's with the syntax after the ":" ?? > > Thanks! > Giuseppe Search "initialization lists" on google. |
Re: What does this syntax mean?
Giuseppe:G: <giuseppegalloneNO@SPAMgmail.com> wrote:
>Hi, the following piece of code is rather obscure for me > >struct Foo >{ > Foo( int _x ) : x(_x) {} >... >}; Foo takes an integer argument. the :x(_x) says to initialize the member variable x using the argument _x. "{}" says that the body of the method is empty, that is, the initialization is the only thing that the constructor does. -- Tim Slattery Slattery_T@bls.gov http://members.cox.net/slatteryt |
| All times are GMT. The time now is 06:38 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.