const_pointer_cast Function
Const 轉型成 shared_ptr。
template <class Ty, class Other>
shared_ptr<Ty> const_pointer_cast(const shared_ptr<Other>& sp);
參數
Ty
傳回的共用指標控制項的型別。Other
這個引數會控制的型別共用指標。Other
這個引數共用指標。
備註
樣板函式傳回空的物件 const_cast<Ty*>(sp.get()) shared_ptr 是否傳回 null 指標;否則會傳回擁有資源。 sp擁有的 shared_ptr Class<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);
}
需求
標題: <memory>
命名空間: std