Sdílet prostřednictvím


Platform::WeakReference – třída

Představuje slabý odkaz na instanci třídy ref.

Syntaxe

class WeakReference

Parametry

Členové

Konstruktory

Člen Popis
WeakReference::WeakReference Inicializuje novou instanci WeakReference třídy.

Metody

Člen Popis
WeakReference::Resolve Vrátí popisovač základní ref třídy nebo nullptr, pokud objekt již neexistuje.

Operátory

Člen Popis
WeakReference::operator= Přiřadí novou hodnotu WeakReference objektu.
WeakReference::operator BoolType Implementuje bezpečný vzor bool.

Poznámky

Samotná třída WeakReference není referenční třídou, a proto nedědí z platform::Object^ a nelze ji použít v podpisu veřejné metody.

WeakReference::operator=

Přiřadí hodnotu weakReference.

Syntaxe

WeakReference& operator=(decltype(__nullptr));
WeakReference& operator=(const WeakReference& otherArg);
WeakReference& operator=(WeakReference&& otherArg);
WeakReference& operator=(const volatile ::Platform::Object^ const otherArg);

Poznámky

Poslední přetížení v seznamu výše umožňuje přiřadit třídu ref proměnné WeakReference. V tomto případě je ref třída downcast na Platform::Object^. Původní typ obnovíte později tak, že ho zadáte jako argument parametru typu ve funkci WeakReference::Resolve<T> member function.

WeakReference::operator BoolType

Implementuje bezpečný logický model pro WeakReference třídy. Není nutné volat explicitně z vašeho kódu.

Syntaxe

BoolType BoolType();

WeakReference::Resolve – metoda (obor názvů platformy)

Vrátí popisovač původní třídy ref, nebo nullptr pokud objekt již neexistuje.

Syntaxe

template<typename T>
T^ Resolve() const;

Parametry

Hodnota vlastnosti / návratová hodnota

Popisovač třídy ref, ke které byl objekt WeakReference dříve přidružen nebo nullptr.

Příklad

Bar^ bar = ref new Bar();
//use bar...

if (bar != nullptr)
{
    WeakReference wr(bar);
    Bar^ newReference = wr.Resolve<Bar>();
}

Všimněte si, že parametr typu je T, nikoli T^.

WeakReference::WeakReference – konstruktor

Poskytuje různé způsoby vytvoření WeakReference.

Syntaxe

WeakReference();
WeakReference(decltype(__nullptr));
WeakReference(const WeakReference& otherArg);
WeakReference(WeakReference&& otherArg);
explicit WeakReference(const volatile ::Platform::Object^ const otherArg);

Příklad

MyClass^ mc = ref new MyClass();
WeakReference wr(mc);
MyClass^ copy2 = wr.Resolve<MyClass>();

Viz také

Platform – obor názvů