다음을 통해 공유


static_pointer_cast Function

Shared_ptr 정적 캐스팅 했습니다.

template <class Ty, class Other>
    shared_ptr<Ty> static_pointer_cast(const shared_ptr<Other>& sp);

매개 변수

  • Ty
    제어 공유 포인터가 반환 된 형식입니다.

  • Other
    제어 공유 포인터로 인수 형식입니다.

  • Other
    공유 인수 포인터입니다.

설명

템플릿 빈 shared_ptr 개체 경우 반환 sp 빈입니다 shared_ptr 개체입니다. 그렇지 않으면 있는 shared_ptr Class<Ty> 소유 하는 리소스를 소유 하는 개체 sp.식 static_cast<Ty*>(sp.get()) 유효 해야 합니다.

예제

 

// std_tr1__memory__static_pointer_cast.cpp 
// compile with: /EHsc 
#include <memory> 
#include <iostream> 
 
struct base 
    { 
    int val; 
    }; 
 
struct derived 
    : public base 
    { 
    }; 
 
int main() 
    { 
    std::shared_ptr<base> sp0(new derived); 
    std::shared_ptr<derived> sp1 = 
        std::static_pointer_cast<derived>(sp0); 
 
    sp0->val = 3; 
    std::cout << "sp1->val == " << sp1->val << std::endl; 
 
    return (0); 
    } 
 
  

요구 사항

헤더: <memory>

네임 스페이스: std

참고 항목

참조

shared_ptr Class

const_pointer_cast Function

dynamic_pointer_cast Function