Created
August 7, 2017 14:14
-
-
Save lexuanquynh/d43e0c759429f10087e8cd1b5987e356 to your computer and use it in GitHub Desktop.
This file contains 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> | |
//singleton design pattern | |
class Hello { | |
private: | |
Hello() { | |
std::cout << "Hello world 7" << std::endl; | |
} | |
public: | |
static Hello* getInstance() { | |
if (instance == NULL) { | |
instance = new Hello(); | |
} | |
} | |
~Hello() { | |
} | |
void releaseInstance() { | |
if (instance) { | |
delete instance; | |
instance = NULL; | |
//std::cout << "Deleted" << std::endl; | |
} | |
} | |
private: | |
static Hello* instance; | |
}; | |
Hello* Hello::instance = NULL; | |
int main() { | |
Hello *objHello; | |
objHello = Hello::getInstance(); | |
objHello->releaseInstance(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment