Perstistence of Class Static Data Members

R

Robert May

Hi,

Can anybody tell me whether the use of static class data members is
any different than using global variables? i.e. do they remain
persistent in memory for the duration of main() execution? Or are
they destroyed if their are no instances of their associated class?

Cheers,
Rob
 
M

Mike Wahler

Robert May said:
Hi,

Can anybody tell me whether the use of static class data members is
any different than using global variables?

Yes, they have different scopes.
i.e. do they remain
persistent in memory for the duration of main() execution?

Yes, they have the same storage duration (static), i.e.
the lifetime of the program invocation.

Or are
they destroyed if their are no instances of their associated class?

No, no instances need exist. The static data is still there.

-Mike
 

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

Forum statistics

Threads
474,183
Messages
2,570,967
Members
47,518
Latest member
RomanGratt

Latest Threads

Top