Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Service {
- public:
- Service() {
- if(s_count++ == 0) {
- s_initialize();
- }
- }
- ~Service() {
- if(--s_count == 0) {
- s_terminate();
- }
- }
- void foo() {
- // do something that requires the resource/system here
- }
- private:
- static int s_count;
- static void s_initialize() {
- // initialize some resource/system here
- }
- static void s_terminate() {
- // terminate some resource/system here
- }
- };
- int Service::s_count = 0; // this is BS by the way C++
- int main() {
- // initializes
- Service service;
- // just reference counts
- Service redundant;
- // operates on the service
- service.foo();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement