0

We can do it on unique pointer. But how to do it on shared pointer? If I do reset, the memory is deleted.

shared_ptr<int> p(new int(10));
int* q = p.release(); //???
user1899020
  • 13,167
  • 21
  • 79
  • 154

1 Answers1

1

You can't do it, because there can be other shared_ptr<int> objects referring to the same int.

usta
  • 6,699
  • 3
  • 22
  • 39