Const转换到的情况。
template <class Ty, class Other>
shared_ptr<Ty> const_pointer_cast(const shared_ptr<Other>& sp);
参数
Ty
返回的共享指针控件的类型。Other
参数控制的类型共享指针。Other
参数共享指针。
备注
模板函数返回空的情况对象 const_cast<Ty*;AMP_gt;(sp.get()) 是否返回null指针;否则它返回拥有资源。sp拥有的 shared_ptr Class<Ty;AMP_gt; 对象。该表达式 const_cast<Ty*;AMP_gt;(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);
}
要求
标头: <memory>
命名空间: std