-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
36 lines (28 loc) · 1.13 KB
/
main.cpp
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
#include <time.h>
#include <stdlib.h>
#include <iostream>
#include "singleton.h"
using namespace std;
int main() {
srand(time(NULL));
cout << "Hello, World!" << endl;
Singleton * a = Singleton::getInstance();
Singleton * b = Singleton::getInstance();
cout << "A:\t" << a << "\t" << a->getSecretNumber() << endl;
cout << "B:\t" << b << "\t" << b->getSecretNumber() << endl;
for (char c = 'C'; c < 'H'; c++) {
Singleton * x = Singleton::getInstance();
cout << c << ":\t" << x << "\t" << x->getSecretNumber() << endl;
}
Singleton * del = Singleton::getInstance();
cout << "Usuwam instancje..." << endl;
del->deleteInstance();
cout << "Pobieram nowa:" << endl;
Singleton * z = Singleton::getInstance();
cout << "Z:\t" << z << "\t" << z->getSecretNumber() << endl;
cout << "\nDisclaimer:\n" <<
"Addres of new instance occur to be the same as first one, " <<
"but it is caused because the new instance is placed in the same place in memory.\n" <<
"The secret_number is new, which proves, that constructor has been used." << endl;
return 0;
}