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