解释未解决的外部C ++

问题描述 投票:0回答:1

我正在制作Minecraft渲染器。从区域文件加载世界时,它将解析的NBT数据存储在无序映射中,其中nbt数据为值,全局块坐标为键。具体来说,unordered_map<pair<int, int>, CompoundTag*>(复合标签是NBT数据)

但是,我遇到了编译时错误,该错误似乎指向无序映射。如下。

错误LNK2001无法解析的外部符号“类std :: unordered_map,结构块,结构std :: hash>,struct std :: equal_to>,class std :: allocator const,struct Chunk>>> __cdecl createChunks(classstd :: unordered_map,类CompoundTag,结构std :: hash>,struct std :: equal_to>,class std :: allocator const,class CompoundTag>>>&,&class Asset&)“(?createChunks @@ YA?AV?$ unordered_map @ U?$ pair @ HH @ std @@ UChunk @@ U?$ hash @ U?$ pair @ HH @ std @@@ 2 @ U?$ equal_to @ U? $ pair @ HH @ std @@@@ 2 @ V?$ allocator @ U?$ pair @ $$ CBU?$ pair @ HH @ std @@ UChunk @@@ std @@@ 2 @@ std @@ AEAV?$ unordered_map @ U?$ pair @ HH @ std @@ VCompoundTag @@ U?$ hash @ U?$ pair @ HH @ std @@@@ 2 @ U?$ equal_to @ U?$ pair @ HH @ std @@@@ 2 @V?$ allocator @ U?$ pair @ $$ CBU?$ pair @ HH @ std @@ VCompoundTag @@@ std @@@ 2 @@ 2 @ AEAVAsset @@@@ Z)

我之前已经解决了无法解决的外部问题,通常是因为我忘记了包含程序需要的外部文件(因此而得名)。但是,这次我可以肯定地说,我拥有了它所需要的一切。我在文件的顶部包含了unordered_map。我已经在其中定义了Chunk的标头包括在内,并且我知道需要自定义构建哈希和equal_to函数,并在包含的标头文件中为它们提供了以下内容。

namespace std
{
    template<>
    struct hash<pair<int32_t, int32_t>>
    {
        size_t operator ()(const pair<int32_t, int32_t>& value) const
        {
            uint64_t key = ((uint64_t)value.first) << 32 | (uint64_t)value.second;
            key ^= (key >> 33);
            key *= 0xff51afd7ed558ccd;
            key ^= (key >> 33);
            key *= 0xc4ceb9fe1a85ec53;
            key ^= (key >> 33);
            return (size_t)key;
        }
    };


    template<>
    struct equal_to<pair<int32_t, int32_t>>
    {
        bool operator ()(const pair<int32_t, int32_t>& v1, const pair<int32_t, int32_t>& v2) const
        {
            return (v1.first == v2.first) && (v1.second == v2.second);
        }
    };
}

我认为我可能需要做的唯一另一件事是提供一个自定义分配器?但是我发现有关在unordered_maps中使用对作为键的所有内容都表明这是不必要的。我有些困惑,不胜感激。如果您有任何疑问或想查看更多代码,请询问。如果您想整体上看一下项目,这是在我的github上,但是,如果您(合理地)不想对整个烂摊子进行分类,请要求对任何内容或其他信息进行澄清。

c++ c++17 unordered-map std-pair
1个回答
0
投票

错误消息很长,但是如果仔细阅读,它表示的是缺少的名为createChunks的函数。

unordered_map只是该函数的返回类型(和参数类型)。

© www.soinside.com 2019 - 2024. All rights reserved.