public member function
<memory>

std::weak_ptr::reset

void reset() noexcept;
Reset pointer
The object becomes empty, as if default constructed.

Parameters

none

Return value

none

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// weak_ptr::reset example
#include <iostream>
#include <memory>

int main () {
  std::shared_ptr<int> sp (new int(10));

  std::weak_ptr<int> wp(sp);

  std::cout << "1. wp " << (wp.expired()?"is":"is not") << " expired\n";

  wp.reset();

  std::cout << "2. wp " << (wp.expired()?"is":"is not") << " expired\n";

  return 0;
}

Output:
1. wp is not expired
2. wp is expired


See also