8/30/09

Explain using static class member ..

A class member declared static is a single instance of that member shared by all instances of this class (that's why it is sometimes termed a class variable, as opposed to object variable). This feature has many uses: for instance, in order to create a file lock, one can use a static bool class member. An object trying to access this file has to check first whether the static (i.e., shared) flag is false. If it is, the object turns the flag on and processes the file safely, since other objects will now find that the flag is now on, and hence -- they cannot access the file. When the object processing the file is done, it has to turn off the flag, enabling another object to access it. How is a static member created?
class fileProc {
FILE *p;
static bool isLocked; //only a declaration; see definition below...
public:
bool isLocked () const {return isLocked; }
};

//somewhere outside the class definition:

bool fileProc::isLocked; //definition; initialized to 'false' by default. Note: no 'static' here

9 comments:

sujitkumar said...

Nice info. Thanks for sharing valuable info about about c++ Faqs. I want to learn c training this tutorial is really helpful. Thanks a lot. Keep sharing on updating tutorials……

Sathyatech said...

Informative post

Keep on updating…

Software Training institute in hyderabad | Software Training courses in hyderabad

gowsalya said...

This blog is the general information for the feature. You got a good work for these blog.We have a developing our creative content of this mind.Thank you for this blog. This for very interesting and useful.
python Training institute in Chennai
python Training institute in Bangalore

sai said...

Well done! Pleasant post! This truly helps me to discover the solutions for my inquiry. Trusting, that you will keep posting articles having heaps of valuable data. You're the best! 
Python Online training
Python Course institute in Bangalore

Anonymous said...

Mind Q Systems provides AWS training in Hyderabad & Bangalore.AWS training designed for students and professionals. Mind Q Provides 100% placement assistance with AWS training.

Mind Q Systems is a Software Training Institute in Hyderabad and Bangalore offering courses on Testing tools, selenium, java, oracle, Manual Testing, Angular, Python, SAP, Devops etc.to Job Seekers, Professionals, Business Owners, and Students. We have highly qualified trainers with years of real-time experience.

Keerthana said...

Amazing write-up!!!Useful posts,Thanks for sharing.
python training in chennai | python training in annanagar | python training in omr | python training in porur | python training in tambaram | python training in velachery

rocky said...

Really awesome artical sir. Very useful interview questions.
Thank you.
Python Training in Chennai

Python Training in Bangalore

Python Training in Hyderabad

Python Training in Coimbatore

Python Training

python online training

python flask training

python flask online training


lavanya said...

Really awesome artical sir. Very useful interview questions.
Thank you.salesforce training in chennai

software testing training in chennai

robotic process automation rpa training in chennai

blockchain training in chennai

devops training in chennai

Reshma said...


Great post. Thanks for sharing such a worthy information.....
Ethical Hacking course in Bangalore
Ethical Hacking Course in Pune

ITUCU