Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 无法编译值为unique\u ptr的google::稀疏\u哈希\u映射_C++_C++11_Gcc - Fatal编程技术网

C++ 无法编译值为unique\u ptr的google::稀疏\u哈希\u映射

C++ 无法编译值为unique\u ptr的google::稀疏\u哈希\u映射,c++,c++11,gcc,C++,C++11,Gcc,我试图编译谷歌的稀疏散列图,但有一个错误。错误消息似乎与使用unique\u ptr有关。删除unique\u ptr后编译成功 google::sparse_hash_map<std::string, std::unique_ptr<int>> testers_; google::sparse\u hash\u map testers; 错误消息如下所示。有什么建议吗?非常感谢 build/libgcc/include/c++/trunk/bits/stl_pa

我试图编译谷歌的稀疏散列图,但有一个错误。错误消息似乎与使用
unique\u ptr
有关。删除
unique\u ptr
后编译成功

  google::sparse_hash_map<std::string, std::unique_ptr<int>> testers_;
google::sparse\u hash\u map testers;
错误消息如下所示。有什么建议吗?非常感谢

build/libgcc/include/c++/trunk/bits/stl_pair.h:127:17: note: explicitly defaulted function was implicitly deleted here
  constexpr pair(const pair&) = default;
            ^

build/libgcc/include/c++/trunk/bits/stl_pair.h:102:11: note: copy constructor of 'pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char>, std::basic_string<char> >, std::unique_ptr<int, std::default_delete<int> > >' is implicitly deleted because field 'second' has a deleted copy constructor
  _T2 second;                /// @c second is a copy of the second object
      ^

/build/libgcc/include/c++/trunk/bits/unique_ptr.h:356:7: note: 'unique_ptr' has been explicitly marked deleted here
  unique_ptr(const unique_ptr&) = delete;
build/libgcc/include/c++/trunk/bits/stl_pair.h:127:17:注意:这里隐式删除了显式默认函数
constexpr pair(const pair&)=默认值;
^
build/libgcc/include/c++/trunk/bits/stl_pair.h:102:11:注意:“pair”的复制构造函数被隐式删除,因为字段“second”有一个已删除的复制构造函数
_T2秒;///@c second是第二个对象的副本
^
/build/libgcc/include/c++/trunk/bits/unique_ptr.h:356:7:注意:“unique_ptr”已在此处明确标记为delete
唯一\u ptr(const unique \u ptr&)=删除;

我认为根本上存在问题

unique_ptr的目的是使指向特定资源的指针只有一个所有者。检索唯一\u ptr副本的最后一个

考虑到容器,这意味着如果有人请求资源,则映射无法保存所指向对象的副本,从而使映射本身无效(即:在第一次“获取”之后,该条目的内部将有一个无效的唯一指针)


我相信Cx11的一些约束禁止编译,从而避免了错误。

我同意其基本原理。但有趣的是,使用std::unordered_map和unique_ptr并没有任何问题。@SuperBald,有趣。我发现按照你的提示:,这似乎是我们正在寻找的答案。非常感谢!这真的是最相关的帖子!