-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingleton.cpp
More file actions
39 lines (31 loc) · 873 Bytes
/
Singleton.cpp
File metadata and controls
39 lines (31 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// Singleton.cpp
// Exam
//
// Created by Max Reshetey on 08/11/2016.
// Copyright © 2016 Max Reshetey. All rights reserved.
//
#include "Singleton.h"
SingletonMazeFactory * SingletonMazeFactory::_instance = nullptr;
namespace Singleton
{
extern void test()
{
cout << "=== Singleton pattern ===\n\n";
// Classic implementation
{
SingletonMazeFactory * factory = SingletonMazeFactory::instance();
cout << "See singleton: " << factory << "\n";
cout << "See singleton: " << SingletonMazeFactory::instance() << "\n";
factory->dealloc();
}
cout << endl;
// Modern design, stack allocation, auto destruction
{
SingletonMazeFactory &factory = SingletonMazeFactory::instanceNew();
cout << "See singleton: " << &factory << "\n";
cout << "See singleton: " << &SingletonMazeFactory::instanceNew() << "\n";
}
cout << endl;
}
}