cplusplus
.com
教程
參考
文章
論壇
C++
教程
參考
文章
論壇
參考
C 庫
<cassert> (assert.h)
<cctype> (ctype.h)
<cerrno> (errno.h)
C++11
<cfenv> (fenv.h)
<cfloat> (float.h)
C++11
<cinttypes> (inttypes.h)
<ciso646> (iso646.h)
<climits> (limits.h)
<clocale> (locale.h)
<cmath> (math.h)
<csetjmp> (setjmp.h)
<csignal> (signal.h)
<cstdarg> (stdarg.h)
C++11
<cstdbool> (stdbool.h)
<cstddef> (stddef.h)
C++11
<cstdint> (stdint.h)
<cstdio> (stdio.h)
<cstdlib> (stdlib.h)
<cstring> (string.h)
C++11
<ctgmath> (tgmath.h)
<ctime> (time.h)
C++11
<cuchar> (uchar.h)
<cwchar> (wchar.h)
<cwctype> (wctype.h)
容器
C++11
<array>
<deque>
C++11
<forward_list>
<list>
<map>
<queue>
<set>
<stack>
C++11
<unordered_map>
C++11
<unordered_set>
<vector>
輸入/輸出
<fstream>
<iomanip>
<ios>
<iosfwd>
<iostream>
<istream>
<ostream>
<sstream>
<streambuf>
多執行緒
C++11
<atomic>
C++11
<condition_variable>
C++11
<future>
C++11
<mutex>
C++11
<thread>
其他
<algorithm>
<bitset>
C++11
<chrono>
C++11
<codecvt>
<complex>
<exception>
<functional>
C++11
<initializer_list>
<iterator>
<limits>
<locale>
<memory>
<new>
<numeric>
C++11
<random>
C++11
<ratio>
C++11
<regex>
<stdexcept>
<string>
C++11
<system_error>
C++11
<tuple>
C++11
<type_traits>
C++11
<typeindex>
<typeinfo>
<utility>
<valarray>
<memory>
類
allocator
C++11
allocator_arg_t
C++11
allocator_traits
auto_ptr
auto_ptr_ref
C++11
bad_weak_ptr
C++11
default_delete
C++11
enable_shared_from_this
C++11
owner_less
C++11
pointer_traits
raw_storage_iterator
C++11
shared_ptr
C++11
unique_ptr
C++11
uses_allocator
C++11
weak_ptr
列舉類
C++11
pointer_safety
函式
C++11
addressof
C++11
align
C++11
allocate_shared
C++11
const_pointer_cast
C++11
declare_no_pointers
C++11
declare_reachable
C++11
dynamic_pointer_cast
C++11
get_deleter
C++11
get_pointer_safety
get_temporary_buffer
C++11
make_shared
return_temporary_buffer
C++11
static_pointer_cast
C++11
undeclare_no_pointers
C++11
undeclare_reachable
uninitialized_copy
C++11
uninitialized_copy_n
uninitialized_fill
uninitialized_fill_n
物件
C++11
allocator_arg
auto_ptr
auto_ptr::~auto_ptr
auto_ptr::auto_ptr
成員函式
auto_ptr::get
auto_ptr::operator->
auto_ptr::operator*
auto_ptr::operator=
auto_ptr::operator
auto_ptr::release
auto_ptr::reset
參考
<memory>
auto_ptr
類模板
<memory>
std::
auto_ptr
template <class X> class auto_ptr;
自動指標 [已棄用]
注意:
此類模板在 C++11 中已被棄用。
unique_ptr
是一個具有類似功能的新工具,但具有更高的安全性(無虛假複製賦值)、增加了功能(
deleters
)和對陣列的支援。有關更多資訊,請參閱
unique_ptr
。
此類模板為指標提供了一個有限的
垃圾回收
機制,允許在
auto_ptr
物件本身被銷燬時自動銷燬其指向的元素。
auto_ptr
物件具有
擁有
分配給它們的指標的特性:一個
auto_ptr
物件擁有一個元素時,負責銷燬它指向的元素並在其自身被銷燬時釋放分配給它的記憶體。解構函式透過呼叫
operator delete
自動完成。
因此,不應有兩個
auto_ptr
物件“擁有”同一個元素,因為兩者最終都會嘗試銷燬它們。當兩個
auto_ptr
物件之間發生賦值操作時,會發生
所有權
轉移,這意味著失去所有權的物件的指標被設定為不再指向該元素(它被設定為
空指標
)。
模板引數
X
被管理物件的型別,別名為成員型別
element_type
.
成員型別
以下別名是...的成員型別
auto_ptr
.
成員型別
定義
說明
element_type
類模板引數(
X
)
被管理物件的型別
成員函式
(建構函式)
構造 auto_ptr 物件
(public 成員函式)
(解構函式)
銷燬 auto_ptr
(public 成員函式)
get
獲取指標
(public 成員函式)
operator*
解引用物件
(public 成員函式)
operator->
解引用物件成員
(public 成員函式)
operator=
釋放並複製 auto_ptr
(public 成員函式)
release
釋放指標
(public 成員函式)
重置
解分配物件並設定新值
(public 成員函式)
(轉換運算子)
轉換運算子
(public 成員函式)