Sdílet prostřednictvím


shared_ptr::operator=

Nahradí vlastnictví prostředku.

shared_ptr& operator=(const shared_ptr& sp);
template<class Other>
    shared_ptr& operator=(const shared_ptr<Other>& sp);
template<class Other>
    shared_ptr& operator=(auto_ptr<Other>& ap);
template<class Other>
    shared_ptr& operator=(auto_ptr<Other>& ap);
template<class Other>
    shared_ptr& operator=(auto_ptr<Other>&& ap);
template<class Other, class Deletor>
    shared_ptr& operator=(unique_ptr<Other, Deletor>&& ap);

Parametry

  • sp
    Sdílené ukazatel ke kopírování.

  • ap
    Ukazatel automatické kopírování.

Poznámky

Všechny operátory snížit počet odkazů na daný zdroj aktuálně vlastněny *this a přiřazení vlastnictví zdroj s názvem sekvencí operand na *this.Pokud počet odkazů klesne na nulu, zdroj uvolněna.Pokud operátor selhání listy *this beze změny.

Příklad

 

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

Požadavky

Záhlaví: <memory>

Obor názvů: std

Viz také

Referenční dokumentace

shared_ptr Class

shared_ptr::reset