Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication31.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <string>
- using namespace std;
- class Semafor{
- private:
- static Semafor* uniq;
- int count;
- Semafor(){
- count=0;
- }
- ~Semafor(){
- }
- public:
- static Semafor* getInstance(){
- if(uniq==NULL)
- uniq=new Semafor();
- uniq->count++;
- if(uniq->count>4)
- throw "Eroare";
- return uniq;
- }
- };
- Semafor* Semafor::uniq=NULL;
- int main()
- {
- try{
- Semafor::getInstance();
- Semafor::getInstance();
- Semafor::getInstance();
- Semafor::getInstance();
- Semafor::getInstance();
- Semafor::getInstance();
- }
- catch(string *s)
- {
- printf("%s\n",s->c_str());
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement