473,498 Members | 1,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jun 27 '08 #1
3 1756
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.
Jun 27 '08 #2
On Sun, 22 Jun 2008 21:02:45 +0200, G: <gi***************@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.
Jun 27 '08 #3
Giuseppe:G: <gi***************@SPAMgmail.comwrote:
>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
Sl********@bls.gov
http://members.cox.net/slatteryt
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
18799
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
3
2977
by: Chris Cioffi | last post by:
I started writing this list because I wanted to have definite points to base a comparison on and as the starting point of writing something myself. After looking around, I think it would be a...
7
2182
by: Jonathan Fine | last post by:
Giudo has suggested adding optional static typing to Python. (I hope suggested is the correct word.) http://www.artima.com/weblogs/viewpost.jsp?thread=85551 An example of the syntax he proposes...
70
8805
by: Roy Yao | last post by:
Does it mean "(sizeof(int))* (p)" or "sizeof( (int)(*p) )" ? According to my analysis, operator sizeof, (type) and * have the same precedence, and they combine from right to left. Then this...
6
1818
by: George Styles | last post by:
Hi, I am trying to work out what a block of C++ does, but I am having trouble understanding the syntax. I know Delphi well, so am happy with objects etc, its just this syntax I dont understand. ...
3
6636
by: RobertTG | last post by:
Someone please translate the code below into English... Particularly the indicated line Thanks function attachComment() { var aForms = document.getElementsByTagName("FORM"); for (var i = 0;...
35
4154
by: wilsonidv | last post by:
Daer All: I have studied C language for just 2~3 months. I'd like to know the critical parts of C, focusing on these. Could anyone has many experiences tell me, please. Thanks and Regards.
132
4492
by: Frederick Gotham | last post by:
If we look at a programming language such as C++: When an updated Standard comes out, everyone adopts it and abandons the previous one. It seems though that things aren't so clear-cut in the C...
92
6110
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
9
1950
by: Jonathan Wood | last post by:
I found the following class on the Web: public class LoginRewriter : IHttpModule { void IHttpModule.Dispose() { } void IHttpModule.Init(HttpApplication app) { app.AuthorizeRequest += new...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7004
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7208
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
4915
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4593
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1423
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
292
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.