Partager via


weak_ptr::operator=

Remplace la propre ressource.

weak_ptr& operator=(const weak_ptr& wp);
template<class Other>
    weak_ptr& operator=(const weak_ptr<Other>& wp);
template<class Other>
    weak_ptr& operator=(const shared_ptr<Other>& sp);

Paramètres

  • Other
    Le type est contrôlé par l'argument shared/weak du pointeur.

  • wp
    Le pointeur faible à copier.

  • sp
    Pointeur partagé à copier.

Notes

Tous les opérateurs libèrent la ressource actuellement désignée par *this et affectent la propriété de la ressource nommée par la séquence d'opérande à *this. Si un opérateur échoue il laisse *this inchangé.

Exemple

 

// std_tr1__memory__weak_ptr_operator_as.cpp 
// compile with: /EHsc 
#include <memory> 
#include <iostream> 
 
int main() 
    { 
    std::shared_ptr<int> sp0(new int(5)); 
    std::weak_ptr<int> wp0(sp0); 
    std::cout << "*wp0.lock() == " << *wp0.lock() << std::endl; 
 
    std::shared_ptr<int> sp1(new int(10)); 
    wp0 = sp1; 
    std::cout << "*wp0.lock() == " << *wp0.lock() << std::endl; 
 
    std::weak_ptr<int> wp1; 
    wp1 = wp0; 
    std::cout << "*wp1.lock() == " << *wp1.lock() << std::endl; 
 
    return (0); 
    } 
 
  

Configuration requise

En-tête: <mémoire>

Espace de noms : std

Voir aussi

Référence

weak_ptr, classe

weak_ptr::reset