weak_ptr::reset

Releases owned resource.

void reset();

Remarks

The member function releases the resource pointed to by *this and converts *this to an empty weak_ptr object.

Example

 

// 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); 
    } 
 
*wp.lock() == 5
wp.expired() == false
wp.expired() == true

Requirements

Header: <memory>

Namespace: std

See Also

Reference

weak_ptr Class

weak_ptr::operator=