[cpp]
#include<iostream>
class finalclass
{
public: static int count;
public:
static finalclass *getinstance()
{
if(count <= 0)
return NULL;
count--;
return new finalclass;
}
static void setcount(int n)
{
count = n;
}
/* static void deleteinstance(finalclass *pinstance)
{
delete pinstance;
pinstance = 0;
}
*/
private:
finalclass(){}
~finalclass(){}
};
int finalclass::count = 0;
int main()
{
finalclass::setcount(3);
finalclass *f1 = finalclass::getinstance();
finalclass *f2 = finalclass::getinstance();
finalclass *f3 = finalclass::getinstance();
if(f3 == NULL)
printf("f3 NULL\n");
else
printf("f3 NOT NULL\n");
finalclass *f4 = finalclass::getinstance();
if(f4 == NULL)
printf("f4 NULL\n");
finalclass *f5 = finalclass::getinstance();
if(f5 == NULL)
printf("f5 NULL\n");
}
#include<iostream>
class finalclass
{
public: static int count;
public:
static finalclass *getinstance()
{
if(count <= 0)
return NULL;
count--;
return new finalclass;
}
static void setcount(int n)
{
count = n;
}
/* static void deleteinstance(finalclass *pinstance)
{
delete pinstance;
pinstance = 0;
}
*/
private:
finalclass(){}
~finalclass(){}
};
int finalclass::count = 0;
int main()
{
finalclass::setcount(3);
finalclass *f1 = finalclass::getinstance();
finalclass *f2 = finalclass::getinstance();
finalclass *f3 = finalclass::getinstance();
if(f3 == NULL)
printf("f3 NULL\n");
else
printf("f3 NOT NULL\n");
finalclass *f4 = finalclass::getinstance();
if(f4 == NULL)
printf("f4 NULL\n");
finalclass *f5 = finalclass::getinstance();
if(f5 == NULL)
printf("f5 NULL\n");
}