替换特定资源。
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 当前拥有的所有减量,并且资源分配的所有权。操作数序列到名为 *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);
}
要求
页眉: <内存>
命名空间: std