다음을 통해 공유


weak_ptr::weak_ptr

weak_ptr를 생성합니다.

weak_ptr();
weak_ptr(const weak_ptr& wp);
template<class Other>
    weak_ptr(const weak_ptr<Other>& wp);
template<class Other>
    weak_ptr(const shared_ptr<Other>& sp);

매개 변수

  • Other
    형식 인수 공유/약한 포인터에 의해 제어.

  • wp
    복사할 약한 포인터입니다.

  • sp
    복사할 공유 포인터입니다.

설명

생성자는 각 피연산자 시퀀스에서 명명 된 리소스를 가리키는 개체를 생성 합니다.

예제

 

// std_tr1__memory__weak_ptr_construct.cpp 
// compile with: /EHsc 
#include <memory> 
#include <iostream> 
 
int main() 
    { 
    std::weak_ptr<int> wp0; 
    std::cout << "wp0.expired() == " << std::boolalpha 
        << wp0.expired() << std::endl; 
 
    std::shared_ptr<int> sp1(new int(5)); 
    std::weak_ptr<int> wp1(sp1); 
    std::cout << "*wp1.lock() == " 
        << *wp1.lock() << std::endl; 
 
    std::weak_ptr<int> wp2(wp1); 
    std::cout << "*wp2.lock() == " 
        << *wp2.lock() << std::endl; 
 
    return (0); 
    } 
 
  

요구 사항

헤더: <memory>

네임 스페이스: std

참고 항목

참조

weak_ptr Class