| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- Decorator
- 43. Multiply Strings
- 715. Range Module
- Class
- Python
- data science
- concurrency
- 30. Substring with Concatenation of All Words
- Convert Sorted List to Binary Search Tree
- iterator
- Generator
- attribute
- 315. Count of Smaller Numbers After Self
- 컴퓨터의 구조
- Python Implementation
- 운영체제
- Regular Expression
- 파이썬
- DWG
- 밴픽
- Python Code
- t1
- 프로그래머스
- kaggle
- LeetCode
- Substring with Concatenation of All Words
- 109. Convert Sorted List to Binary Search Tree
- 시바견
- Protocol
- shiba
Archives
- Today
- Total
Scribbling
[C++] Smart pointers 본문
1. unique_ptr
int main() {
auto intPtr{ make_unique<int>(42) };
cout << *intPtr << endl;
}
get() method give access to the internal pointer;
int main() {
auto intPtr{ make_unique<int>(42) };
cout << *intPtr << endl;
cout << *intPtr.get() << endl;
}
unique_ptr also has reset(), release() methods.
2. shared_ptr
unique_ptr does not allow copying; If the pointer needs to be copied from else, use shared_ptr.
int main() {
auto intPtr{ make_shared<int>(42) };
auto copiedPtr{ intPtr };
cout << *copiedPtr << endl;
cout << *copiedPtr.get() << endl;
}
'Computer Science > C++' 카테고리의 다른 글
| [C++] 전문가를 위한 C++ - Chapter 8 (0) | 2023.10.07 |
|---|---|
| [C++] find, deque, bfs, structured binding (0) | 2023.09.30 |
| [C++] 전문가를 위한 C++ - Chapter 2 (1) | 2023.09.21 |
| [C++] 2d DP table with vector (0) | 2023.09.19 |
| [C++] 전문가를 위한 C++ - Chapter 1 (0) | 2023.09.15 |