forked from jzplp/Cpp-Primer-Answer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
26 lines (22 loc) · 855 Bytes
/
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
#include<iostream>
#include<string>
#include<memory>
#include "shared_ptr2.h"
#include "DebugDelete.h"
template class shared_ptr2<int>;
int main()
{
shared_ptr2<int> sp(new int(3), DebugDelete()) ,sp1;;
shared_ptr2<std::string> ssp(new std::string("12345"));
std::cout << *sp << std::endl;
std::cout << sp.unique() << " " << sp.use_count() << " " << *(sp.get()) << std::endl;
std::cout << ssp.unique() << " " << ssp.use_count() << " " << *(ssp.get()) << std::endl;
sp = sp;
sp1 = sp;
std::cout << sp1.unique() << " " << sp1.use_count() << " " << *(sp1.get()) << std::endl;
sp1 = std::move(sp);
std::cout << sp1.unique() << " " << sp1.use_count() << " " << *(sp1.get()) << std::endl;
ssp.reset(new std::string("qwert"), DebugDelete());
std::cout << ssp.unique() << " " << ssp.use_count() << " " << *(ssp.get()) << std::endl;
return 0;
}