473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

What does line 162 do ?

159: static PartsList GlobalPartsList;
160: };
161:
162: PartsList PartsList::GlobalPartsList;

I would understand if it initialized the object
GlobalPartsList with some value, but as it is now, it seems to me
without purpose.

Thanks,

Rafael
Jun 27 '08 #1
13 1435
Rafael Anschau wrote:
159: static PartsList GlobalPartsList;
160: };
161:
162: PartsList PartsList::GlobalPartsList;

I would understand if it initialized the object
GlobalPartsList with some value, but as it is now, it seems to me
without purpose.
It _defines_ the static data member. Read up on static data members.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 27 '08 #2
Yes, my text says it initializes or defines it there. That line 159
only declares it.
But initializes it, defines it with what ? What it does is to make it
possible to later assign
a value ?

[]´s

Rafael

On May 9, 12:26 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Rafael Anschau wrote:
159: static PartsList GlobalPartsList;
160: };
161:
162: PartsList PartsList::GlobalPartsList;
I would understand if it initialized the object
GlobalPartsList with some value, but as it is now, it seems to me
without purpose.

It _defines_ the static data member. Read up on static data members.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 27 '08 #3
On May 9, 12:26 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>Rafael Anschau wrote:
>>159: static PartsList GlobalPartsList;
160: };
161:
162: PartsList PartsList::GlobalPartsList;
>>I would understand if it initialized the object
GlobalPartsList with some value, but as it is now, it seems to me
without purpose.

It _defines_ the static data member. Read up on static data members.
Rafael Anschau wrote:
Yes, my text says it initializes or defines it there. That line 159
only declares it.
But initializes it, defines it with what ? What it does is to make it
possible to later assign
a value ?

[]´s
Please do not top post. Message rearranged.

Since GlobalPartsList is static, there can be only one in the program.
There can be only one definition.

Line 162 is simply *the* definition. Line 159 is the declaration. You can
not define a static variable inside a class declaration, you can only
declare it. So outside the class declaration you need the definition, which
you have.

It may make more sense if it was an int.

class foo
{
static int bar;
};

int foo::bar = 42;

Your PartsList PartsList::GlobalPartsList; is doing the same thing, it is
just default constructed.
--
Jim Langston
ta*******@rocketmail.com
Jun 27 '08 #4
Thanks, but same question.

int foo::bar = 42;//OK, =42
int foo::bar; //??

[]´s

Rafael
Jun 27 '08 #5
Thanks but same question:

int foo::bar = 42; //Ok, =42
int foo::bar;// ?? =??

[]´s

Rafael
Jun 27 '08 #6
Rafael Anschau wrote:
Thanks, but same question.

int foo::bar = 42;//OK, =42
int foo::bar; //??
If your question is what value 'foo::bar' gets, the answer is 0.
[]´s
Sorry, I for one don't understand. "Brackets's"?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 27 '08 #7
On May 9, 8:43 am, Rafael Anschau <rafael.ansc...@gmail.comwrote:
Yes, my text says it initializes or defines it there. That line 159
only declares it.
But initializes it, defines it with what ? What it does is to make it
possible to later assign
a value ?
When an object is initialised it calls the objects constructor.
So line 162 creates the object and calls the objects constructor (see
constructor for PartsList). Once it has been constructed you can now
call all the public methods available in PartsList.
PartsList::GlobalPartsList.doSomthing()

Jun 27 '08 #8
Thank you now I get it. The purpose is to make members avalible
and run the constructor. Great.

[]´s

Rafael
Jun 27 '08 #9
>Sorry, I for one don't understand. "Brackets's"?

That´s an old 80´s 90´s (70´s ?) electronic compliment.

[]´s

Rafael
Jun 27 '08 #10
On 9 mai, 20:09, Rafael Anschau <rafael.ansc...@gmail.comwrote:
Thank you now I get it. The purpose is to make members
avalible and run the constructor.
Or not. Even if the object doesn't have a constructor, you need
a definition. Very basically, it's the definition which
allocates the memory for the object (or causes the
compiler/linker to allocate it).

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #11
Rafael Anschau wrote:
>>Sorry, I for one don't understand. "Brackets's"?

That´s an old 80´s 90´s (70´s ?) electronic compliment.

[]´s
But it's probably supposed to use the apostrohpe (') and not the
french "accent aigu" over an empty space (´).

Jun 27 '08 #12
Rafael Anschau wrote:
Thank you now I get it. The purpose is to make members avalible
and run the constructor. Great.
No, it isn't. Think of the declaration as an entry in the table of contents
in a book. It tells you which chapters exist and how to find them, but it
doesn't contain the actual chapter text. So you need to add the chapter
content somwehere to your book, just like you need to define the static
member variable somewhere, since otherwise, the TOC entry leads to nowhere.

Jun 27 '08 #13
Rafael Anschau wrote:
>>Sorry, I for one don't understand. "Brackets's"?

That´s an old 80´s 90´s (70´s ?) electronic compliment.

[]´s
But it's probably supposed to be using an apostrophe and not an acute accent
over an empty space.

Jun 27 '08 #14

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

Similar topics

125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
1
by: vishal | last post by:
What does #line 182 parser.y mean in a C program?
5
by: Matthew Zhou | last post by:
I check the ISO 9899 standard, \r (carriage return) Movesthe active position to the initial position of the current line. What does it do? How to input? I tried to use Flex to check this...
2
by: Dilip7597 | last post by:
Hello Guys, while checking one of the program, I found one difficulty with my program. there was a condition like (!!a), and I don't know what does it means. So if anybody knows...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.