Compartir a través de


shared_ptr::operator=

Reemplaza el recurso propio.

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
    el puntero compartido a copiar.

  • ap
    el puntero auto a copiar.

Comentarios

Los operadores todo decrement que el recuento de referencias para el recurso poseyó actualmente por *this y la propiedad de la asignación de recursos denominado por la secuencia de operando a *this.Si el recuento de referencias baja en cero, libera el recurso.Si se produce un operador permite *this sin cambios.

Ejemplo

 

// 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

encabezado: <memoria>

espacio de nombres: std

Vea también

Referencia

shared_ptr Class

shared_ptr::reset