Partilhar via


shared_ptr::operator=

Substitui o recurso de propriedade.

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);

Parâmetros

  • sp
    O ponteiro compartilhado a ser copiada.

  • ap
    O ponteiro automático a ser copiada.

Comentários

Os operadores qualquer redução a contagem de referência do recurso atualmente propriedade *this e atribuir a propriedade de recursos denominado pela sequência do operando a *this. Se a contagem de referência se encaixa a zero, o recurso será liberado. Se um operador falha permite que *this inalterado.

Exemplo

 

// 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); 
    } 
 
  

Requisitos

Cabeçalho: <memória>

Namespace: std

Consulte também

Referência

Classe shared_ptr

shared_ptr::reset