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;
}
Senate Approves Trump’s Bid to Cancel Foreign Aid and Funds for NPR and PBS
Stations
-
The bill to claw back $9 billion in congressionally approved spending
passed over the objections of Republicans who said it abdicated the
legislative branc...
1 hour ago
No comments:
Post a Comment