forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex12_10.cpp
36 lines (32 loc) · 1006 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
35
36
/***************************************************************************
* @file The code is for the exercises in C++ Primmer 5th Edition
* @author Alan.W
* @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 <vector>
#include <string>
#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;
}