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