在C++ 11标准的12.8 / 15段中定义:



这是否意味着:

struct st {
  int a;
  int b;
  // ...
};

// ...
void do_smt(st tmp) {
  st lala(std::move(tmp));
  // ...
}

// ...
int main(int argc, char* argv[]) {
  st test(1, 2);
  do_smt(std::move(test));
}

没有move构造函数将可以工作吗?

最佳答案

是的,它无需指定move构造函数即可工作;在您的示例中,编译器可能会通过初始化lala而不是test来优化移动操作;检查有关汇编程序的输出。

关于c++ - (POD)结构上是否需要 move 构造函数?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18346426/

10-11 22:50
查看更多