Namespaces
Variants

std:: auto_ptr

From cppreference.net
Memory management library
( exposition only* )
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
( until C++20* )
( until C++20* )
( until C++20* )

Garbage collector support (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
헤더 파일에 정의됨 <memory>
template < class T > class auto_ptr ;
(1) (C++11에서 사용 중단됨)
(C++17에서 제거됨)
template <> class auto_ptr < void > ;
(2) (C++11에서 사용 중단됨)
(C++17에서 제거됨)

auto_ptr new expression 을 통해 획득한 객체를 관리하며, auto_ptr 자체가 소멸될 때 해당 객체를 삭제하는 스마트 포인터입니다. 동적으로 할당된 객체에 대한 예외 안전성을 제공하고, 함수로 동적으로 할당된 객체의 소유권을 전달하며, 함수로부터 동적으로 할당된 객체를 반환하는 데 사용될 수 있습니다.

auto_ptr 을 복사하면 포인터를 복사하고 소유권을 대상으로 이전합니다: auto_ptr 의 복사 생성과 복사 할당 모두 우측 인수를 수정하며, "복사본"은 원본과 동일하지 않습니다. 이러한 특이한 복사 의미론 때문에 auto_ptr 은 표준 컨테이너에 배치될 수 없습니다. std::unique_ptr 이 용도와 다른 용도로 선호됩니다. (C++11부터)

2) void 타입에 대한 특수화가 제공되며, 이는 element_type typedef를 선언하지만 멤버 함수는 선언하지 않습니다.

문서 전체에서 참조되는 추가적인 클래스 템플릿 auto_ptr_ref 가 있습니다. 이것은 auto_ptr 에 대한 참조를 보유하는 구현 정의 타입입니다. 구현체는 이 템플릿에 다른 이름을 제공하거나, 이를 반환하는 함수나 매개변수로 받는 함수를 다른 방식으로 구현할 수 있습니다.

목차

멤버 타입

멤버 타입 정의
element_type T

멤버 함수

새로운 auto_ptr 을 생성함
(public member function)
auto_ptr 와 관리되는 객체를 파괴함
(public member function)
다른 auto_ptr 로부터 소유권을 이전함
(public member function)
관리되는 포인터를 다른 타입의 포인터로 변환함
(public member function)
Observers
관리되는 객체에 대한 포인터를 반환함
(public member function)
관리되는 객체에 접근함
(public member function)
Modifiers
관리되는 객체를 교체함
(public member function)
관리되는 객체의 소유권을 해제함
(public member function)