| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- 파이썬
- 315. Count of Smaller Numbers After Self
- Class
- concurrency
- kaggle
- Regular Expression
- 운영체제
- Substring with Concatenation of All Words
- Decorator
- Python Implementation
- 109. Convert Sorted List to Binary Search Tree
- 밴픽
- DWG
- shiba
- Protocol
- 30. Substring with Concatenation of All Words
- 프로그래머스
- t1
- 715. Range Module
- 43. Multiply Strings
- 컴퓨터의 구조
- Convert Sorted List to Binary Search Tree
- 시바견
- Python Code
- Python
- iterator
- data science
- Generator
- LeetCode
- attribute
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 |