Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

move constructor for pointer type?

Tags:

c++

c++11

This is a simple question but I can't manage to find it on google:

Is there a special move constructor for integral type(including pointers)

For instance if I do:

int* a = new int(2);
int* b = std::move(a);

Is it guaranteed to point to NULL? How about if a and b were int?

like image 705
lezebulon Avatar asked Feb 27 '26 17:02

lezebulon


1 Answers

is a guaranteed to point to NULL ?

No, it will be unchanged. Initialisation of built-in types will never modify the initialiser. Only initialisation of a class type with a move constructor (or an evil non-constant copy constructor, such as auto_ptr) could modify it.

For example, if you used std::unique_ptr rather than dumb pointers, then a would be empty after the initialisation of b.

How about if a and b were ints?

Still no.

like image 90
Mike Seymour Avatar answered Mar 01 '26 10:03

Mike Seymour