In the below programme i use one boolean variable named check , which is being accessed inside main function by two objects of Tst1 and Test2 . But the value of check variable is not maintained in the programme . we can use static but i want to know some alternative way ..could anyone give me some hints on it ?
Thanks in advance .
Inside jointdeatils.h
1 2 3 4 5 6 7 8 9 10 11
#pragma once
class Jointdetails
{
public:
Jointdetails(void);
~Jointdetails(void);
bool check;
};
The only solution I can see is to keep one static pointer and one static instance counter. Both start out at zero. When the first instance is constructed, the pointer is initialized to a dynamically allocated object. Once the last instance is destructed, the pointer is destructed and reset. This approach has three problems:
1. It's complex.
2. It makes no sense to do this unless your static object is big or it has special semantics.
3. It's not thread-safe.