shared_ptr::operator=
取代特定資源。
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);
參數
sp
複製的共用指標。ap
複製的自動指標。
備註
運算子都會以 *this 目前擁有之資源的參考次數 (Reference Count) 並指定運算元序列命名之資源的擁有權。 *this。 如果參考計數小於零,會釋放資源。 如果運算子失敗 *this 它會保持不變。
範例
// 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);
}
需求
標題: <memory>
命名空間: std