c++ - 移动指针类型的构造函数?

标签 c++ c++11

这是一个简单的问题,但我无法在谷歌上找到它:

整数类型(包括指针)是否有专门的移动构造函数

例如,如果我这样做:

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 而不是哑指针,则 ab 初始化后将为空。

How about if a and b were ints?

还是不行

关于c++ - 移动指针类型的构造函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18235072/

相关文章:

c++ - 简而言之,GCC 选项 -fipa-pta 的作用是什么?

c++ - C++ 中的 "Python dictionary"功能?

c++ - 模板参数数量错误

c++ - 为什么成员 `float x` 在 main() 中为对象 `0.` 和 `a` 初始化为 `b`?

c++ - c++ 中 make_unique 和 make_unique 与 reference_wrapper 的区别

c++ - 在内部类中使用引用模板参数

c++ - [C++] 嵌套类在制作链迭代器时显示 "does not name a type"错误

c++ - 可变数量的构造函数参数取决于整数模板

c++ - 使用正确的编译器标志在每个平台上进行相同的模拟

c++ - 堆栈溢出与 std::make_unique 但不是与原始指针