const_pointer_cast
Const 转换为的情况下。
template <class Ty, class Other>
shared_ptr<Ty> const_pointer_cast(const shared_ptr<Other>& sp);
参数
Ty
返回的共享指针控制的类型。Other
参数控制的类型共享指针。Other
共享指针参数。
备注
模板函数的情况下返回空 const_cast<Ty*>(sp.get()) 对象是否返回 null 指针;否则返回的资源由 spshared_ptr 类拥有的<Ty> 对象。 const_cast<Ty*>(sp.get()) 绑定表达式是有效的。
示例
// std_tr1__memory__const_pointer_cast.cpp
// compile with: /EHsc
#include <memory>
#include <iostream>
int main()
{
std::shared_ptr<int> sp0(new int);
std::shared_ptr<const int> sp1 =
std::const_pointer_cast<const int>(sp0);
*sp0 = 3;
std::cout << "sp1 == " << *sp1 << std::endl;
return (0);
}
要求
页眉: <内存>
命名空间: std