-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice6.cpp
More file actions
47 lines (33 loc) · 1.1 KB
/
practice6.cpp
File metadata and controls
47 lines (33 loc) · 1.1 KB
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
40
41
42
43
44
45
46
47
#include <iostream>
#include <memory>
using namespace std;
/*
WEAK POINTERS
*/
int main()
{
int a = 7530;
auto sh_ptr_1 = make_shared<int>(a);
auto sh_ptr_2 = sh_ptr_1;
auto sh_ptr_3 = sh_ptr_1;
auto sh_ptr_4 = sh_ptr_1;
auto sh_ptr_5 = sh_ptr_1;
cout << "I. *sh_ptr_1: " << *sh_ptr_1 << endl;
cout << "I. *sh_ptr_2: " << *sh_ptr_2 << endl;
cout << "I. *sh_ptr_3: " << *sh_ptr_3 << endl;
cout << "I. *sh_ptr_4: " << *sh_ptr_4 << endl;
cout << "I. *sh_ptr_5: " << *sh_ptr_5 << endl;
cout << "--------------------------------" << endl
<< endl;
weak_ptr<int> wk_pointer = sh_ptr_1;
cout << "Number of owners: " << wk_pointer.use_count() << endl;
sh_ptr_1.reset();
sh_ptr_2.reset();
cout << "Number of owners: " << wk_pointer.use_count() << endl;
cout << "(sh_ptr_4 > sh_ptr_5): " << (sh_ptr_4 > sh_ptr_5) << endl;
cout << "(sh_ptr_4 < sh_ptr_5): " << (sh_ptr_4 < sh_ptr_5) << endl;
cout << wk_pointer.owner_before(sh_ptr_3) << endl;
cout << "--------------------------------" << endl
<< endl;
return 1;
}