Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > For classes with static members

Reply
Thread Tools

For classes with static members

 
 
parag_paul@hotmail.com
Guest
Posts: n/a
 
      12-18-2007
Can a class with out any instances present have it static members
updated.

If yes, on which object does the update happen.
-Parag
 
Reply With Quote
 
 
 
 
Kira Yamato
Guest
Posts: n/a
 
      12-18-2007
On 2007-12-18 15:00:56 -0500, "(E-Mail Removed)"
<(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
 
Rahul
Guest
Posts: n/a
 
      12-19-2007
On Dec 19, 1:00 am, "(E-Mail Removed)" <(E-Mail Removed)>
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...
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      12-19-2007
On Dec 19, 4:45 am, Rahul <(E-Mail Removed)> wrote:
> On Dec 19, 1:00 am, "(E-Mail Removed)"
> <(E-Mail Removed)> 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:(E-Mail Removed)
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

 
Reply With Quote
 
Rahul
Guest
Posts: n/a
 
      12-19-2007
On Dec 19, 3:00 pm, James Kanze <(E-Mail Removed)> wrote:
> On Dec 19, 4:45 am, Rahul <(E-Mail Removed)> wrote:
>
> > On Dec 19, 1:00 am, "(E-Mail Removed)"
> > <(E-Mail Removed)> 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:(E-Mail Removed)
> 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


 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      12-19-2007
Rahul wrote:
> On Dec 19, 3:00 pm, James Kanze <(E-Mail Removed)> wrote:
>> On Dec 19, 4:45 am, Rahul <(E-Mail Removed)> wrote:
>>
>>> On Dec 19, 1:00 am, "(E-Mail Removed)"
>>> <(E-Mail Removed)> 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.
 
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
Why can nsmc, local classes or anonymous classes have static members? Rit Java 23 01-03-2010 05:54 PM
Classes - Adding members to members Daz C++ 5 05-07-2006 09:25 AM
Difference between static final members and final static members(if any)? JFCM Java 4 02-07-2006 11:32 AM
Static classes with static members Ben ASP .Net 3 06-01-2004 07:43 PM
inner classes and static members maxw_cc Java 6 12-04-2003 03:13 AM



Advertisments