shared_ptr::operator=
Zastępuje posiadanych zasobów.
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
Wskaźnik udostępnionych do skopiowania.ap
Wskaźnik auto, aby skopiować.
Uwagi
Wszystkie operatory zmniejszy licznik odniesienia dla zasobu aktualnie własnością *this i przypisać własność zasobu o nazwie przez sekwencję operand *this.Jeśli licznika odwołań spada do zera, zasób jest zwalniana.Jeżeli operator nie pozostawia *this bez zmian.
Przykład
// 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);
}
Wymagania
Nagłówek: <memory>
Obszar nazw: std