Hi guys ,i came across coding in a book where they given the below program and named it as singleton class.but here we are able to create 2nd object and also call constructor for second object (only here do we check the status of count and exit from the program after creation of 2nd object).so what if i am right??n what if i can modify this program and make it create only one object??
#include<iostream.h>
class sample
{
static int count;
public:
sample()
{
if(count==1)
exit(0);
printf("OBJ:%d\n",count);
count++;
}
};
int sample::count;
int main()
{
sample s1;
sample s2;
return(0);
}