when p is destroyed, then the object it is pointing to will be destroyed too |
destroyed, to be specific, using the default deleter (since you didn't specify a different one), which simply calls
delete
on the managed pointer. Calling
delete
to the address of
b
is undefined behavior because that address was not obtained by a call to
new
.
If you're giving unique_ptr a pointer you did not obtain from
new
, you also need to give it a deleter that won't call
delete
. For example, a unique pointer holding
FILE*
obtained from
fopen
would also hold a pointer to
fclose
as the deleter.
the vector will be deallocated and size will be 0. |
no, once a vector is destroyed, it does not have any size. It does not exist.