Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > What does this syntax mean?

Reply
Thread Tools

What does this syntax mean?

 
 
Giuseppe:G:
Guest
Posts: n/a
 
      06-22-2008
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
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      06-22-2008
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.
 
Reply With Quote
 
 
 
 
David Côme
Guest
Posts: n/a
 
      06-22-2008
On Sun, 22 Jun 2008 21:02:45 +0200, 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 ":" ??
>
> Thanks!
> Giuseppe


Search "initialization lists" on google.
 
Reply With Quote
 
Tim Slattery
Guest
Posts: n/a
 
      06-23-2008
Giuseppe:G: <> 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) 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

http://members.cox.net/slatteryt
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax Checker that's better than the normal syntax checker Jacob Grover Ruby 5 07-18-2008 05:07 AM
Syntax error? What syntax error? Assignment fo default values? Mark Richards Perl Misc 3 11-18-2007 05:01 PM
Syntax bug, in 1.8.5? return not (some expr) <-- syntax error vsreturn (not (some expr)) <-- fine Good Night Moon Ruby 9 07-25-2007 04:51 PM
[ANN] SqlStatement 1.0.0 - hide the syntax of SQL behind familiarruby syntax Ken Bloom Ruby 3 10-09-2006 06:46 PM
Syntax highligth with textile: Syntax+RedCloth ? gabriele renzi Ruby 2 12-31-2005 02:44 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57