code refactoring: fix memory leaks, code style, etc.

This commit is contained in:
Jakub Vojvoda
2019-01-31 19:57:40 +01:00
parent a8681552c4
commit a0b0ea4f8e
24 changed files with 960 additions and 566 deletions

View File

@@ -15,16 +15,28 @@
* has private static variable to hold one instance of the class
* and method which gives us a way to instantiate the class
*/
class Singleton {
class Singleton
{
public:
static Singleton *get() {
if (instance == NULL) {
static Singleton* get()
{
if ( !instance )
{
instance = new Singleton();
}
}
return instance;
}
void tell() {
static void restart()
{
if ( instance )
{
delete instance;
}
}
void tell()
{
std::cout << "This is Singleton." << std::endl;
// ...
}
@@ -42,5 +54,7 @@ Singleton* Singleton::instance = nullptr;
int main()
{
Singleton::get()->tell();
Singleton::restart();
return 0;
}