When do we want to declare static object

R

ron_werbin

Hi there,

In what cases will we want to declare our objects static?
for example

*.cpp:

static String xStr;

Than you for any help,

Ron
 
M

Moonlit

Hi,

Wel I usually have a logging object around that I want to be able to access
from any method or in any file. I usually have that object in the file with
the main routine ( 'CLog Log( "Filename.log" );'. (and 'extern CLog Log;' in
the header file).

Another case would be a class variable. For instance to serialize classes to
and from storage (be it memory disk or somehting else). I have a virtual
function that returns the name of the class. On serializing I first write
that class name (this makes sure a derived will be correctly deserialized).
When deserializing an object located on the heap first the classname is read
then the class is created by mapping the class name in a map<ClassName,
CreateMethod>. The created object is then deserialized in the allocated
space.


--


Regards, Ron AF Greve

http://moonlit.xs4all.nl
 

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,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top