共用方式為


weak_ptr::reset

會釋放資源。

void reset();

備註

成員函式釋放資源指向 *this 並轉換 *this 為空白 weak_ptr 物件。

範例

 

// std_tr1__memory__weak_ptr_reset.cpp 
// compile with: /EHsc 
#include <memory> 
#include <iostream> 
 
int main() 
    { 
    std::shared_ptr<int> sp(new int(5)); 
    std::weak_ptr<int> wp(sp); 
    std::cout << "*wp.lock() == " << *wp.lock() << std::endl; 
    std::cout << "wp.expired() == " << std::boolalpha 
        << wp.expired() << std::endl; 
 
    wp.reset(); 
    std::cout << "wp.expired() == " << std::boolalpha 
        << wp.expired() << std::endl; 
 
    return (0); 
    } 
 
  

需求

標題: <memory>

命名空間: std

請參閱

參考

weak_ptr Class

weak_ptr::operator=