Reset unique_ptr<int[]> to existing int array of different size

Viewed 53

I have this code:

auto p = make_unique<int[]>(5);
auto tmp = new int[10];
// Some other code.
p = tmp;    <--- Does not work.

I have a unique_ptr p. I want to reassign the pointed array to another existing array (tmp). I would have expected the assignment to delete[] the old array and set it to tmp.

How can I achieve this result? Using p.reset(tmp) works, but how does p know about the new size?

0 Answers
Related