-
Notifications
You must be signed in to change notification settings - Fork 3k
/
ex12_10.cpp
34 lines (30 loc) · 959 Bytes
/
ex12_10.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
/***************************************************************************
* @file The code is for the exercises in C++ Primmer 5th Edition
* @author Yue Wang
* @date 23 DEC 2013
* @remark
***************************************************************************/
//
// Exercise 12.10:
// Explain whether the following call to the process function defined on page
// 464 is correct. If not, how would you correct the call?
// correct.
#include <iostream>
#include <memory>
void process(std::shared_ptr<int> ptr)
{
std::cout << "inside the process function:" << ptr.use_count() << "\n";
}
int main()
{
std::shared_ptr<int> p(new int(42));
process(std::shared_ptr<int>(p));
/**
* codes below shows how the reference count change.
*/
std::cout << p.use_count() << "\n";
auto q = p;
std::cout << p.use_count() << "\n";
std::cout << "the int p now points to is:" << *p << "\n";
return 0;
}