Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // c1.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include <iostream>
- using namespace std;
- class Singleton {
- static Singleton* instance;
- int data;
- // Private constructor so that no objects can be created.
- Singleton() {}
- public:
- static Singleton* getInstance() {
- if (!instance) {
- instance = new Singleton;
- cout << "new class" << endl;
- }
- return instance;
- }
- };
- //Initialize pointer to zero so that it can be initialized in first call to getInstance
- Singleton* Singleton::instance = 0;
- int main() {
- Singleton* s = Singleton::getInstance();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement