Created
September 27, 2016 19:39
-
-
Save itayB/90074f6601aa0a0162e5e4911e240cca to your computer and use it in GitHub Desktop.
Singlton Example (Design Pattern)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| class Singlton { | |
| public: | |
| static Singlton* getInstance() { | |
| static Singlton* instance = nullptr; | |
| if (instance == nullptr) | |
| instance = new Singlton(); | |
| return instance; | |
| } | |
| void print() { | |
| cout << "I'm singlton!" << endl; | |
| } | |
| }; | |
| int main() { | |
| Singlton* s = Singlton::getInstance(); | |
| s->print(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment