Sphere: Related Content
#include <iostream>
using namespace std;
class Singleton
{
public:
static Singleton* Instance();
protected:
Singleton();
//Singleton(const Singleton&);
//Singleton& operator= (const Singleton&);
private:
static Singleton* pinstance;
};
Singleton* Singleton::pinstance = 0;// initialize pointer
Singleton* Singleton::Instance ()
{
if (pinstance == 0) // is it the first call?
{
pinstance = new Singleton; // create sole instance
}
return pinstance; // address of sole instance
}
Singleton::Singleton()
{
//... perform necessary instance initializations
cout << "Calling Protected Constructor" << endl;
}
int main()
{
Singleton *p1 = Singleton::Instance();
Singleton *p2 = p1->Instance();
Singleton & ref = * Singleton::Instance();
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.
48 minutes ago
No comments:
Post a Comment