For classes with static members

P

parag_paul

Can a class with out any instances present have it static members
updated.

If yes, on which object does the update happen.
-Parag
 
K

Kira Yamato

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.
 
R

Rahul

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...
 
J

James Kanze

On Dec 19, 1:00 am, "(e-mail address removed)"
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.
 
R

Rahul

That's true for most variables, but not for static POD types,
which are automatically zero initialized before any code is run.


The initialization of a static variable has nothing to do with
memory allocation.


What is the initialization meant for?
 
I

Ian Collins

Rahul said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top