| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"" |
| Date: |
18 Dec 2007 02:00:56 PM |
| Object: |
For classes with static members |
Can a class with out any instances present have it static members
updated.
If yes, on which object does the update happen.
-Parag
.
|
|
| User: "Kira Yamato" |
|
| Title: Re: For classes with static members |
18 Dec 2007 02:05:35 PM |
|
|
On 2007-12-18 15:00:56 -0500, "parag_paul@hotmail.com"
<parag_paul@hotmail.com> said:
Can a class with out any instances present have it static members
updated.
Yes.
If yes, on which object does the update happen.
None. Static member variables belong to the class, not to any object.
--
-kira
.
|
|
|
|
| User: "Rahul" |
|
| Title: Re: For classes with static members |
18 Dec 2007 09:45:59 PM |
|
|
On Dec 19, 1:00 am, "parag_p...@hotmail.com" <parag_p...@hotmail.com>
wrote:
Can a class with out any instances present have it static members
updated.
If yes, on which object does the update happen.
-Parag
But yes one needs to make sure that they are initialized once before
any usage.
The initialization makes sure that the memory is allocated for the
static member variables.
Any usage of static member variables without initialization could
cause unresolved external symbol linker error...
.
|
|
|
| User: "James Kanze" |
|
| Title: Re: For classes with static members |
19 Dec 2007 04:00:14 AM |
|
|
On Dec 19, 4:45 am, Rahul <sam_...@yahoo.co.in> wrote:
On Dec 19, 1:00 am, "parag_p...@hotmail.com"
<parag_p...@hotmail.com> wrote:
Can a class with out any instances present have it static
members updated.
If yes, on which object does the update happen.
But yes one needs to make sure that they are initialized once
before any usage.
That's true for most variables, but not for static POD types,
which are automatically zero initialized before any code is run.
The initialization makes sure that the memory is allocated for
the static member variables.
The initialization of a static variable has nothing to do with
memory allocation.
Any usage of static member variables without initialization
could cause unresolved external symbol linker error...
You'll likely get an unresolved external symbol error from the
linker if you fail to define the symbol, but the linker doesn't
care in the least about initialization.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34
.
|
|
|
| User: "Rahul" |
|
| Title: Re: For classes with static members |
19 Dec 2007 04:23:57 AM |
|
|
On Dec 19, 3:00 pm, James Kanze <james.ka...@gmail.com> wrote:
On Dec 19, 4:45 am, Rahul <sam_...@yahoo.co.in> wrote:
On Dec 19, 1:00 am, "parag_p...@hotmail.com"
<parag_p...@hotmail.com> wrote:
Can a class with out any instances present have it static
members updated.
If yes, on which object does the update happen.
But yes one needs to make sure that they are initialized once
before any usage.
That's true for most variables, but not for static POD types,
which are automatically zero initialized before any code is run.
The initialization makes sure that the memory is allocated for
the static member variables.
The initialization of a static variable has nothing to do with
memory allocation.
What is the initialization meant for?
Any usage of static member variables without initialization
could cause unresolved external symbol linker error...
You'll likely get an unresolved external symbol error from the
linker if you fail to define the symbol, but the linker doesn't
care in the least about initialization.
--
James Kanze (GABI Software) email:james.ka...@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34
.
|
|
|
| User: "Ian Collins" |
|
| Title: Re: For classes with static members |
19 Dec 2007 04:28:59 AM |
|
|
Rahul wrote:
On Dec 19, 3:00 pm, James Kanze <james.ka...@gmail.com> wrote:
On Dec 19, 4:45 am, Rahul <sam_...@yahoo.co.in> wrote:
On Dec 19, 1:00 am, "parag_p...@hotmail.com"
<parag_p...@hotmail.com> wrote:
Can a class with out any instances present have it static
members updated.
If yes, on which object does the update happen.
But yes one needs to make sure that they are initialized once
before any usage.
That's true for most variables, but not for static POD types,
which are automatically zero initialized before any code is run.
The initialization makes sure that the memory is allocated for
the static member variables.
The initialization of a static variable has nothing to do with
memory allocation.
What is the initialization meant for?
To initialise the state of the variable, just like any other. Leaving a
static member uninitialised doesn't mean it's not there.
--
Ian Collins.
.
|
|
|
|
|
|
|

|
Related Articles |
|
|