Should i delete a moved from dynamic pointer

Viewed 2457

I understand how to move an object, for example:

int a(5), b(6);
int c(std::move(a)); // move constructor
c = std::move(b);    // move assignment

I understand the common implementation of a custom move constructor (which takes the ownership of a dynamic pointer and sets the moved-from pointer to nullptr.)

But I haven't found anything about moving a dynamically allocated pointer itself. I need confirmation that the following code is legal:

int *p(new int(42));
int val(std::move(*p));
delete p; // I think this is no longer necessary. Is it?

So, is it allowed to move a dynamic pointer?

3 Answers
Related