Created
August 10, 2017 10:09
-
-
Save mathieu-b/0eb8f029650e09375c369fc1b90ac448 to your computer and use it in GitHub Desktop.
Singleton lifecycle.
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
/****************************************************************************** | |
Online C++ Compiler. | |
Code, Compile, Run and Debug C++ program online. | |
Write your code in this editor and press "Run" button to compile and execute it. | |
https://www.onlinegdb.com/online_c++_compiler | |
*******************************************************************************/ | |
#include <iostream> | |
#include <string> | |
void printy(std::string msg) | |
{ | |
std::cout << "MSG: " << msg << std::endl; | |
} | |
class Gino { | |
public: | |
static Gino & getInstance() | |
{ | |
printy("Gino::getInstance()"); | |
static Gino instance; | |
return instance; | |
} | |
void sayHello() | |
{ | |
printy("Gino says: Hello!"); | |
} | |
private: | |
Gino() | |
{ | |
printy("Gino::Gino()"); | |
} | |
~Gino() | |
{ | |
printy("Gino::~Gino()"); | |
} | |
}; | |
int main() | |
{ | |
printy("=== C++ Singleton life cycle ==="); | |
printy("Entered main() ..."); | |
Gino::getInstance().sayHello(); | |
printy("... Exiting main() ."); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment