我想获取存储在unordered_map中的unique_ptr。我使用下面的代码:unique_ptr的unordered_map:无法从迭代器中获取值
#include <unordered_map>
#include <memory>
int *function()
{
std::unordered_map< int, std::unique_ptr<int> > hash;
auto iterator=hash.find(5);
return iterator->second().get();
}
当我尝试编译这个(GCC 4.7.2),我收到以下错误:
test.cpp: In function ‘int* function()’:
test.cpp:9:29: error: no match for call to ‘(std::unique_ptr<int>)()’
我不明白什么是错的这个代码。就好像我需要使用另一种方法从迭代器中提取引用,但我知道没有办法做到这一点。
Shachar
D'oh!谢谢。 Mia culpa。 –