Sphere: Related Content
#include <iostream>
using namespace std;
class Singleton
{
private:
static bool instanceFlag;
static Singleton *single;
Singleton()
{
//private constructor
cout << "Calling private constructor" << endl;
}
public:
static Singleton* getInstance();
void method();
~Singleton()
{
instanceFlag = false;
}
};
bool Singleton::instanceFlag = false;
Singleton* Singleton::single = NULL;
Singleton* Singleton::getInstance()
{
//if(! instanceFlag)
//{
single = new Singleton();
//instanceFlag = true;
return single;
//}
/*
else
{
return single;
}
*/
}
void Singleton::method()
{
cout << "Method of the singleton class" << endl;
}
int main()
{
Singleton *sc1,*sc2;
sc1 = Singleton::getInstance();
sc1->method();
sc2 = Singleton::getInstance();
sc2->method();
sc2 = Singleton::getInstance();
sc2->method();
return 0;
}
SG60 commemorations to kick off with New Year celebrations in city centre,
17 heartland sites
-
Singapore marks 60 years of independence in 2025 and ONE Countdown will be
the first in a series of events celebrating the milestone.
37 minutes ago
No comments:
Post a Comment