Skip to content

Instantly share code, notes, and snippets.

@lexuanquynh
Created August 7, 2017 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lexuanquynh/d43e0c759429f10087e8cd1b5987e356 to your computer and use it in GitHub Desktop.
Save lexuanquynh/d43e0c759429f10087e8cd1b5987e356 to your computer and use it in GitHub Desktop.
#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