名稱空間
變體
操作

std::weak_ptr 的推導指引

來自 cppreference.com
< cpp‎ | memory‎ | weak ptr
 
 
記憶體管理庫
(僅作說明*)
未初始化記憶體演算法
(C++17)
(C++17)
(C++17)
受約束的未初始化
記憶體演算法
C 庫

分配器
記憶體資源
垃圾回收支援
(C++11)(直到 C++23)
(C++11)(直到 C++23)
(C++11)(直到 C++23)
(C++11)(直到 C++23)
(C++11)(直到 C++23)
(C++11)(直到 C++23)
未初始化儲存
(直到 C++20*)
(直到 C++20*)
顯式生命週期管理
 
 
定義於標頭檔案 <memory>
template< class T >
weak_ptr( std::shared_ptr<T> ) -> weak_ptr<T>;
(C++17 起)

std::weak_ptr 提供了一個推導指引,以處理隱式推導指引遺漏的邊緣情況。

[編輯] 示例

#include <memory>
 
int main()
{
    auto p = std::make_shared<int>(42);
    std::weak_ptr w{p}; // explicit deduction guide is used in this case
}