| title | Platform::WeakReference Class | Microsoft Docs | |
|---|---|---|
| ms.custom | ||
| ms.date | 12/30/2016 | |
| ms.technology | cpp-windows | |
| ms.reviewer | ||
| ms.suite | ||
| ms.tgt_pltfrm | ||
| ms.topic | language-reference | |
| f1_keywords |
|
|
| ms.assetid | 8cfe1977-a8c7-4b7b-b539-25c77ed4c5f1 | |
| caps.latest.revision | 4 | |
| author | ghogen | |
| ms.author | ghogen | |
| manager | ghogen |
Represents a weak reference to an instance of a ref class.
class WeakReference | Member | Description |
|---|---|
| WeakReference::WeakReference | Initializes a new instance of the WeakReference class. |
| Member | Description |
|---|---|
| WeakReference::Resolve | Returns a handle to the underlying ref class, or nullptr if the object no longer exists. |
| Member | Description |
|---|---|
| WeakReference::operator= | Assigns a new value to the WeakReference object. |
| WeakReference::operator BoolType | Implements the safe bool pattern. |
The WeakReference class itself is not a ref class and therefore it does not inherit from Platform::Object^ and cannot be used in the signature of a public method.
Assigns a value to a WeakReference.
WeakReference& operator=(decltype(__nullptr));
WeakReference& operator=(const WeakReference& otherArg);
WeakReference& operator=(WeakReference&& otherArg);
WeakReference& operator=(const volatile ::Platform::Object^ const otherArg); The last overload in the list above enables you to assign a ref class to a WeakReference variable. In this case the ref class is downcast to Platform::Object^. You restore the original type later by specifying it as the argument for the type parameter in the WeakReference::Resolve<T> member function.
Implements the safe bool pattern for the WeakReference class. Not to be called explicitly from your code.
BoolType BoolType() Returns a handle to the original ref class, or nullptr if the object no longer exists.
template<typename T>
T^ Resolve() const A handle to the ref class that the WeakReference object was previously associated with, or nullptr.
This is the description for a Code Example.
Bar^ bar = ref new Bar();
//use bar...
if (bar != nullptr)
{
WeakReference wr(bar);
Bar^ newReference = wr.Resolve<Bar>();
}
Note that the type parameter is T, not T^.
Provides various ways to construct a WeakReference.
WeakReference();
WeakReference(decltype(__nullptr));
WeakReference(const WeakReference& otherArg);
WeakReference(WeakReference&& otherArg);
explicit WeakReference(const volatile ::Platform::Object^ const otherArg); MyClass^ mc = ref new MyClass();
WeakReference wr(mc);
MyClass^ copy2 = wr.Resolve<MyClass>();