共用方式為


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