Namespaces
Variants

deduction guides for std::weak_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 >
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}; // 此情况下使用了显式推导指南
}