这是一个简单的问题,但我无法在谷歌上找到它:
整数类型(包括指针)是否有专门的移动构造函数
例如,如果我这样做:
int* a = new int(2);
int* b = std::move(a);
是否保证指向NULL?如果 a 和 b 是 int
怎么样?
最佳答案
is a guaranteed to point to NULL ?
不,它将保持不变。内置类型的初始化永远不会修改初始化程序。只有使用移动构造函数(或邪恶的非常量复制构造函数,例如 auto_ptr
)初始化类类型才能修改它。
例如,如果您使用 std::unique_ptr
而不是哑指针,则 a
在 b
初始化后将为空。
How about if
a
andb
were ints?
还是不行
关于c++ - 移动指针类型的构造函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18235072/