-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlec01_1_shared_ptr.cpp
More file actions
38 lines (32 loc) · 979 Bytes
/
lec01_1_shared_ptr.cpp
File metadata and controls
38 lines (32 loc) · 979 Bytes
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
//
// Tutorial Author: shapelim@kaist.ac.kr (임형태)
#include <pcl/PCLPointCloud2.h>
#include <memory>
#include <vector>
#include <iostream>
using namespace std;
int main(int argc, char**argv) {
// 선언
std::shared_ptr<vector<int> > vec_ptr(new vector<int>());
vector<int> data = {1, 2, 3, 4, 5};
cout<<vec_ptr<<endl;
// 0x55e3cc53ce70 (달라질 수 있음)
// 문법: *shared_ptr에 데이터를 복사하겠다는 의미
*vec_ptr = data;
for (int i = 0; i < vec_ptr->size(); ++i) {
cout << (*vec_ptr)[i] << ", ";
}
cout << endl;
// 1, 2, 3, 4, 5,
cout<<vec_ptr<<endl;
// 0x55e3cc53ce70 (달라질 수 있으나, 12번 줄과 똑같음!)
// 선언 2
std::shared_ptr<vector<int> > vec_ptr2;
vec_ptr2.reset(new vector<int>(3, 5));
for (int i = 0; i < vec_ptr2->size(); ++i) {
cout << (*vec_ptr2)[i] << ", ";
}
cout << endl;
// 5, 5, 5,
return 0;
}