相关疑难解决方法(0)

Visual Studio 2017是否需要显式移动构造函数声明?

下面的代码可以使用Visual Studio 2015成功编译,但使用Visual Studio 2017失败.Visual Studio 2017报告:

错误C2280:"std :: pair :: pair(const std :: pair&)":尝试引用已删除的函数

#include <unordered_map>
#include <memory>

struct Node
{
  std::unordered_map<int, std::unique_ptr<int>> map_;
  // Uncommenting the following two lines will pass Visual Studio 2017 compilation
  //Node(Node&& o) = default;
  //Node() = default;
};

int main()
{
  std::vector<Node> vec;
  Node node;
  vec.push_back(std::move(node));
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

看起来Visual Studio 2017显式需要移动构造函数声明.是什么原因?

c++ move-constructor visual-studio-2017

14
推荐指数
3
解决办法
1163
查看次数

标签 统计

c++ ×1

move-constructor ×1

visual-studio-2017 ×1