std::enable_shared_from_this::weak_from_this

From cppreference.com
 
 
Utilities library
Type support (basic types, RTTI, type traits)
Dynamic memory management
Error handling
Program utilities
Variadic functions
Date and time
Function objects
(C++11)
Relational operators
Optional and any
(C++17)
(C++17)
Pairs and tuples
(C++11)
(C++17)
Swap, forward and move
(C++14)
(C++11)
(C++11)
Type operations
(C++11)
(C++17)
 
 
 
std::weak_ptr<T> weak_from_this();
(1) (since C++17)
std::weak_ptr<T const> weak_from_this() const;
(2) (since C++17)

Returns a std::weak_ptr<T> that tracks ownership of *this by all existing std::shared_ptr that refer to *this.

Contents

[edit] Notes

This is a copy of the the private mutable weak_ptr member that is part of enabled_shared_from_this.

[edit] Return value

std::weak_ptr<T> that shares ownership of *this with pre-existing std::shared_ptrs

[edit] Exceptions

2)
noexcept specification:  
noexcept
  

[edit] Example

[edit] See also

(C++11)
smart pointer with shared object ownership semantics
(class template)