다음을 통해 공유


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
    공유 인수 포인터입니다.

설명

템플릿 빈 shared_ptr 개체 경우 반환 const_cast<Ty*>(sp.get()) ; null 포인터를 반환 합니다. 그렇지 않으면 있는 shared_ptr Class<Ty> 소유 하는 리소스를 소유 하는 개체 sp.식 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

참고 항목

참조

shared_ptr Class

dynamic_pointer_cast Function

static_pointer_cast Function