winrt::weak_ref struct template (C++/WinRT)
A type representing a weak reference to a C++/WinRT object or interface. For more info, and code examples, see Strong and weak references in C++/WinRT.
template <typename T>
struct weak_ref
typename T
The type of C++/WinRT object or interface a weak reference to which is represented by the weak_ref object. This is the type of the weak reference's target.
Minimum supported SDK: Windows SDK version 10.0.17134.0 (Windows 10, version 1803)
Namespace: winrt
Header: %WindowsSdkDir%Include<WindowsTargetPlatformVersion>\cppwinrt\winrt\base.h (included by default)
Constructor | Description |
---|---|
weak_ref::weak_ref constructor | Initializes a new instance of the weak_ref struct, optionally with a copy of the input data. |
Function | Description |
---|---|
weak_ref::get function | Increments the reference count, and retrieves the C++/WinRT object or interface weakly referenced by the weak_ref object. The way to determine whether or not a weak_ref can be resolved to a strong reference is to call get and try. |
Operator | Description |
---|---|
weak_ref::operator bool | Checks whether the weak_ref object owns a weak reference or a nullptr . The way to determine whether or not a weak_ref can be resolved to a strong reference is to call weak_ref::get and try. |
Initializes a new instance of the weak_ref struct, optionally with a copy of the input data.
weak_ref(std::nullptr_t = nullptr) noexcept;
weak_ref(T const& object);
weak_ref(com_ptr<T> const& object);
object
A C++/WinRT object or interface or smart pointer that initializes the weak_ref object.
Increments the reference count, and retrieves the C++/WinRT object or interface weakly referenced by the weak_ref object. The way to determine whether or not a weak_ref can be resolved to a strong reference is to call get and try.
auto get() const noexcept;
The C++/WinRT object or interface weakly referenced by the weak_ref object, or nullptr
if the weak reference's target has been destroyed.
Checks whether the weak_ref object owns a weak reference or a nullptr
. The way to determine whether or not a weak_ref can be resolved to a strong reference is to call weak_ref::get and try.
explicit operator bool() const noexcept;
true
if the weak_ref object owns a weak reference; false
if the weak_ref object owns a nullptr
.