c++ - 使用 std::unordered_map 的模板实例化警告

标签 c++ visual-c++ std unordered-map

我有一个由 glm 库提供的 IVector3 类型:

using IVector3 = glm::ivec3;

我有一个 IVector3s 的哈希函数:

struct IVector3Hash
{
    std::size_t operator()(IVector3 const& i) const noexcept
    {
        std::size_t seed = 0;
        boost::hash_combine(seed, i.x);
        boost::hash_combine(seed, i.y);
        boost::hash_combine(seed, i.z);
        return seed;
    }
};

我正在尝试将 IVector3 映射到 unordered_map 中的 float :

std::unordered_map<IVector3, float, IVector3Hash> g_score;

但是,当我尝试在此映射中放置一个值时,我收到一条警告,提示我需要查看对函数模板实例化的引用:

g_score.emplace(from_node->index, 0);

1>c:\users\accou\documents\pathfindingexamples\c++ library\pathfindinglib\pathfindinglib\pathfinding.cpp(44): note: see reference to function template instantiation 'std::pair<std::_List_iterator<std::_List_val<std::_List_simple_types<_Ty>>>,boo 
l> std::_Hash<std::_Umap_traits<_Kty,float,std::_Uhash_compare<_Kty,_Hasher,_Keyeq>,_Alloc,false>>::emplace<IVector3&,int>(IVector3 &,int &&)' being compiled
1>        with
1>        [
1>            _Ty=std::pair<const IVector3,float>,
1>            _Kty=IVector3,
1>            _Hasher=IVector3Hash,
1>            _Keyeq=std::equal_to<IVector3>,
1>            _Alloc=std::allocator<std::pair<const IVector3,float>>
1>        ]

我查看了 std::pair 和 std::unordered_map 的文档,但看不出我做错了什么。代码可以编译,但如果使用其他编译器,我不希望出现错误。

感谢您的帮助:)

编辑以包括完整的警告文本:https://pastebin.com/G1EdxKKe

最佳答案

我对冗长的错误输出感到困惑,但实际错误是因为我试图 emplace (...) 使用 int 而不是 float 作为 map 所需。

更改为:

g_score.emplace(from_node->index, 0.0f);

解决了这个问题。

关于c++ - 使用 std::unordered_map 的模板实例化警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49514688/

相关文章:

C++ 精确计时器 time.h boost::posix_time

c++ - 使用 VS2012 编译 libffi 失败并出现 fatal error LNK1281 : Unable to generate SAFESEH image

c++ - 如何将 IHTMLDocument2 ->get_body ->get_innerHTML 变成小写字符串?

c++11 使用 std::swap 与 operator=(T&&) 清除容器

c++ - 使用指向我的数组的指针在 C++ 中给我一个 "Unhandled exception"?

c++ - 是否有具有用户定义的碰撞处理程序的 std::unique 风格的库算法?

c++ - Visual Studio 如何将 boost::function 与/GR- 一起使用,而 GCC 不能与 -fno-rtti 一起使用?

c++ - 当 vector<int> 长度增加时,如何设置断点?

c++ - 为什么 std::bind1st 被认为是 "almost unusable"?

c++ - 使用自定义分配器调整大小