std::shared_ptr<T>:: operator=
From cppreference.net
<
cpp
|
memory
|
shared ptr
C++
Memory management library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::shared_ptr
| Member functions | ||||
|
shared_ptr::operator=
|
||||
| Modifiers | ||||
| Observers | ||||
|
(C++17)
|
||||
|
(
until C++20*
)
|
||||
|
(C++26)
|
||||
|
(C++26)
|
||||
| Non-member functions | ||||
|
(until C++20)
(until C++20)
(until C++20)
(until C++20)
(until C++20)
(C++20)
|
||||
|
functions
(
until C++26*
)
|
||||
| Helper classes | ||||
|
(C++20)
|
||||
| Deduction guides (C++17) |
|
shared_ptr
&
operator
=
(
const
shared_ptr
&
r
)
noexcept
;
|
(1) | |
|
template
<
class
Y
>
shared_ptr & operator = ( const shared_ptr < Y > & r ) noexcept ; |
(2) | |
|
shared_ptr
&
operator
=
(
shared_ptr
&&
r
)
noexcept
;
|
(3) | |
|
template
<
class
Y
>
shared_ptr & operator = ( shared_ptr < Y > && r ) noexcept ; |
(4) | |
|
template
<
class
Y
>
shared_ptr & operator = ( std:: auto_ptr < Y > && r ) ; |
(5) |
(C++11에서 사용 중단됨)
(C++17에서 제거됨) |
|
template
<
class
Y,
class
Deleter
>
shared_ptr & operator = ( std:: unique_ptr < Y, Deleter > && r ) ; |
(6) | |
관리되는 객체를 r 이 관리하는 객체로 교체합니다.
만약
*
this
가 이미 객체를 소유하고 있으며 그것이 객체를 소유하는 마지막
shared_ptr
이고,
r
가
*
this
와 동일하지 않다면, 해당 객체는 소유된 삭제자를 통해 파괴됩니다.
1,2)
r
가 관리하는 객체의 소유권을 공유합니다. 만약
r
가 객체를 관리하지 않는다면,
*
this
도 객체를 관리하지 않습니다. 다음 코드와 동등합니다:
shared_ptr
<
T
>
(
r
)
.
swap
(
*
this
)
.
3,4)
shared_ptr
를
r
에서 이동 할당합니다. 할당 후,
*
this
는
r
의 이전 상태 사본을 포함하며,
r
는 비어 있습니다.
shared_ptr
<
T
>
(
std
::
move
(
r
)
)
.
swap
(
*
this
)
와 동등합니다.
5)
r
가 관리하는 객체의 소유권을
*
this
로 이전합니다.
r
가 객체를 관리하지 않는 경우,
*
this
도 객체를 관리하지 않습니다. 대입 후,
*
this
는 이전에
r
가 보유하던 포인터를 포함하며,
use_count
(
)
==
1
입니다; 또한
r
는 비어 있게 됩니다.
shared_ptr
<
T
>
(
r
)
.
swap
(
*
this
)
와 동등합니다.
6)
r
가 관리하는 객체의 소유권을
*
this
로 이전합니다.
r
와 연관된 삭제자는 관리 객체의 향후 삭제를 위해 저장됩니다.
r
는 호출 후 객체를 관리하지 않습니다.
shared_ptr
<
T
>
(
std
::
move
(
r
)
)
.
swap
(
*
this
)
와 동등합니다.
목차 |
매개변수
| r | - | 소유권을 공유하거나 획득할 다른 스마트 포인터 |
반환값
* this
참고 사항
구현 시 임시
shared_ptr
객체를 생성하지 않고도 요구사항을 충족할 수 있습니다.
예외
5,6)
구현에서 정의된 예외를 던질 수 있습니다.
예제
|
이 섹션은 불완전합니다
이유: 예제 없음 |
참고 항목
|
관리되는 객체를 교체합니다
(public member function) |